VideoModel.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*****************************************************************************
  2. * VideoModel.swift
  3. *
  4. * Copyright © 2018 VLC authors and VideoLAN
  5. * Copyright © 2018 Videolabs
  6. *
  7. * Authors: Soomin Lee <bubu@mikan.io>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. class VideoModel: MediaLibraryBaseModel {
  12. typealias MLType = VLCMLMedia
  13. var updateView: (() -> Void)?
  14. var files = [VLCMLMedia]()
  15. var indicatorName: String = NSLocalizedString("MOVIES", comment: "")
  16. required init(medialibrary: VLCMediaLibraryManager) {
  17. medialibrary.addObserver(self)
  18. }
  19. func isIncluded(_ item: VLCMLMedia) {
  20. }
  21. func append(_ item: VLCMLMedia) {
  22. files.append(item)
  23. }
  24. }
  25. extension VideoModel: MediaLibraryObserver {
  26. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddVideo video: [VLCMLMedia]) {
  27. video.forEach({ append($0) })
  28. updateView?()
  29. }
  30. }
  31. extension VLCMLMedia {
  32. @objc func formatDuration(ofMedia media: VLCMLMedia) -> String {
  33. return String(format: "%@ - %@",
  34. VLCTime(int: Int32(media.duration())),
  35. ByteCountFormatter.string(fromByteCount: Int64(media.mainFile().size()),
  36. countStyle: .file))
  37. }
  38. }