Przeglądaj źródła

VLCMediaLibraryManager: Listen to NewFileAdded notification

Soomin Lee 7 lat temu
rodzic
commit
8edeead8e4
1 zmienionych plików z 15 dodań i 0 usunięć
  1. 15 0
      SharedSources/VLCMediaLibraryManager.swift

+ 15 - 0
SharedSources/VLCMediaLibraryManager.swift

@@ -10,6 +10,15 @@
  * Refer to the COPYING file of the official project for license.
  *****************************************************************************/
 
+extension Notification.Name {
+    static let VLCNewFileAddedNotification = Notification.Name("NewFileAddedNotification")
+}
+
+// For objc
+extension NSNotification {
+    @objc static let VLCNewFileAddedNotification = Notification.Name.VLCNewFileAddedNotification
+}
+
 @objc protocol MediaLibraryObserver: class {
     @objc optional func medialibrary(_ medialibrary: VLCMediaLibraryManager,
                       didUpdateVideo video: [VLCMLMedia])
@@ -56,6 +65,8 @@ class VLCMediaLibraryManager: NSObject {
     override init() {
         super.init()
         setupMediaLibrary()
+        NotificationCenter.default.addObserver(self, selector: #selector(reload),
+                                               name: .VLCNewFileAddedNotification, object: nil)
     }
 
     // MARK: Private
@@ -95,6 +106,10 @@ class VLCMediaLibraryManager: NSObject {
 
     // MARK: Internal
 
+    @objc private func reload() {
+        medialib.reload()
+    }
+
     /// Returns number of *ALL* files(audio and video) present in the medialibrary database
     func numberOfFiles() -> Int {
         var media = medialib.audioFiles(with: .filename, desc: false)