VideoModel.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. files = medialibrary.media(ofType: .video)
  19. }
  20. func isIncluded(_ item: VLCMLMedia) {
  21. }
  22. func append(_ item: VLCMLMedia) {
  23. files.append(item)
  24. }
  25. }
  26. extension VideoModel: MediaLibraryObserver {
  27. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddVideo video: [VLCMLMedia]) {
  28. video.forEach({ append($0) })
  29. updateView?()
  30. }
  31. }
  32. extension VLCMLMedia {
  33. @objc func formatDuration(ofMedia media: VLCMLMedia) -> String {
  34. return String(format: "%@ - %@",
  35. VLCTime(int: Int32(media.duration())),
  36. ByteCountFormatter.string(fromByteCount: Int64(media.mainFile().size()),
  37. countStyle: .file))
  38. }
  39. }