AudioModel.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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: MediaLibraryBaseModel {
  12. typealias MLType = VLCMLMedia
  13. var updateView: (() -> Void)?
  14. var files = [VLCMLMedia]()
  15. var indicatorName: String = NSLocalizedString("SONGS", comment: "")
  16. required init(medialibrary: VLCMediaLibraryManager) {
  17. medialibrary.addObserver(self)
  18. // created too late so missed the callback asking if he has anything
  19. files = medialibrary.media(ofType: .audio)
  20. }
  21. func isIncluded(_ item: VLCMLMedia) {
  22. }
  23. func append(_ item: VLCMLMedia) {
  24. // need to check more for duplicate and stuff
  25. files.append(item)
  26. }
  27. }
  28. extension AudioModel: MediaLibraryObserver {
  29. func medialibrary(_ medialibrary: VLCMediaLibraryManager, didAddAudio audio: [VLCMLMedia]) {
  30. audio.forEach({ append($0) })
  31. updateView?()
  32. }
  33. }