Преглед на файлове

media discoverer: add support for custom monitoring locations

Felix Paul Kühne преди 9 години
родител
ревизия
5788eb6642
променени са 4 файла, в които са добавени 16 реда и са изтрити 9 реда
  1. 2 0
      Sources/VLCAppDelegate.m
  2. 2 0
      Sources/VLCHTTPUploaderController.m
  3. 6 0
      Sources/VLCMediaFileDiscoverer.h
  4. 6 9
      Sources/VLCMediaFileDiscoverer.m

+ 2 - 0
Sources/VLCAppDelegate.m

@@ -143,6 +143,8 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
         [[MLMediaLibrary sharedMediaLibrary] applicationWillStart];
 
         VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
+        NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+        discoverer.directoryPath = [searchPaths firstObject];
         [discoverer addObserver:self];
         [discoverer startDiscovering];
     };

+ 2 - 0
Sources/VLCHTTPUploaderController.m

@@ -140,8 +140,10 @@
         [_httpServer stop];
         return true;
     }
+#if TARGET_OS_IOS
     // clean cache before accepting new stuff
     [self cleanCache];
+#endif
 
     // Initialize our http server
     _httpServer = [[HTTPServer alloc] init];

+ 6 - 0
Sources/VLCMediaFileDiscoverer.h

@@ -28,6 +28,12 @@
 
 @interface VLCMediaFileDiscoverer : NSObject
 
+/**
+ * the path the discoverer will monitor
+ * \note _MUST_ be set before starting the discovery
+ */
+@property (readwrite, retain, nonatomic) NSString *directoryPath;
+
 - (void)addObserver:(id<VLCMediaFileDiscovererDelegate>)delegate;
 - (void)removeObserver:(id<VLCMediaFileDiscovererDelegate>)delegate;
 

+ 6 - 9
Sources/VLCMediaFileDiscoverer.m

@@ -20,7 +20,6 @@ const float MediaTimerInterval = 2.f;
     NSMutableArray *_observers;
     dispatch_source_t _directorySource;
 
-    NSString *_directoryPath;
     NSArray *_directoryFiles;
     NSMutableDictionary *_addedFilesMapping;
     NSTimer *_addMediaTimer;
@@ -95,7 +94,12 @@ const float MediaTimerInterval = 2.f;
 
 - (void)startDiscovering
 {
-    _directoryPath = [self directoryPath];
+    if (!_directoryPath) {
+        APLog(@"file discovery failed, no path was set");
+        return;
+    } else
+        APLog(@"will discover files in path: '%@'", _directoryPath);
+
     _directoryFiles = [self directoryFiles];
 
     int const folderDescriptor = open([_directoryPath fileSystemRepresentation], O_EVTONLY);
@@ -143,13 +147,6 @@ const float MediaTimerInterval = 2.f;
 
 #pragma mark - directory watcher delegate
 
-- (NSString *)directoryPath
-{
-    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
-    NSString *directoryPath = searchPaths[0];
-    return directoryPath;
-}
-
 - (void)directoryDidChange
 {
     NSArray *foundFiles = [self directoryFiles];