AudioModel.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*****************************************************************************
  2. * AudioModel.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 AudioModel: MLBaseModel {
  12. typealias MLType = VLCMLMedia
  13. var updateView: (() -> Void)?
  14. var files = [VLCMLMedia]()
  15. var medialibrary: VLCMediaLibraryManager
  16. var indicatorName: String = NSLocalizedString("SONGS", comment: "")
  17. required init(medialibrary: VLCMediaLibraryManager) {
  18. self.medialibrary = medialibrary
  19. medialibrary.addObserver(self)
  20. // created too late so missed the callback asking if he has anything
  21. files = medialibrary.media(ofType: .audio)
  22. }
  23. func isIncluded(_ item: VLCMLMedia) {
  24. }
  25. func append(_ item: VLCMLMedia) {
  26. // need to check more for duplicate and stuff
  27. files.append(item)
  28. }
  29. }
  30. // MARK: - Sort
  31. extension AudioModel {
  32. func sort(by criteria: VLCMLSortingCriteria) {
  33. // FIXME: Currently if sorted by name, the files are sorted by filename but displaying title
  34. files = medialibrary.media(ofType: .audio, sortingCriteria: criteria, desc: false)
  35. updateView?()
  36. }
  37. }
  38. extension AudioModel: MediaLibraryObserver {
  39. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAudio audio: [VLCMLMedia]) {
  40. audio.forEach({ append($0) })
  41. updateView?()
  42. }
  43. }