VideoModel.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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: MLBaseModel {
  12. typealias MLType = VLCMLMedia
  13. var updateView: (() -> Void)?
  14. var files = [VLCMLMedia]()
  15. var medialibrary: VLCMediaLibraryManager
  16. var indicatorName: String = NSLocalizedString("MOVIES", comment: "")
  17. required init(medialibrary: VLCMediaLibraryManager) {
  18. self.medialibrary = medialibrary
  19. medialibrary.addObserver(self)
  20. files = medialibrary.media(ofType: .video)
  21. }
  22. func isIncluded(_ item: VLCMLMedia) {
  23. }
  24. func append(_ item: VLCMLMedia) {
  25. files.append(item)
  26. }
  27. }
  28. extension VideoModel: MediaLibraryObserver {
  29. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddVideo video: [VLCMLMedia]) {
  30. video.forEach({ append($0) })
  31. updateView?()
  32. }
  33. }
  34. extension VLCMLMedia {
  35. @objc func formatDuration(ofMedia media: VLCMLMedia) -> String {
  36. return String(format: "%@ - %@",
  37. VLCTime(int: Int32(media.duration())),
  38. ByteCountFormatter.string(fromByteCount: Int64(media.mainFile().size()),
  39. countStyle: .file))
  40. }
  41. }