Prechádzať zdrojové kódy

HTTP connection: allow enqueued playback of multiple uploads

The first to reach 10% of uploaded data will win and play first
Felix Paul Kühne 9 rokov pred
rodič
commit
49bc98b1e3
1 zmenil súbory, kde vykonal 35 pridanie a 10 odobranie
  1. 35 10
      Sources/VLCHTTPConnection.m

+ 35 - 10
Sources/VLCHTTPConnection.m

@@ -41,7 +41,7 @@
     UInt64 _contentLength;
     UInt64 _receivedContent;
 #if TARGET_OS_TV
-    BOOL _playbackStarted;
+    NSMutableArray *_receivedFiles;
 #endif
 }
 @end
@@ -580,12 +580,9 @@
     long long percentage = ((_receivedContent * 100) / _contentLength);
     APLog(@"received %lli kB (%lli %%)", _receivedContent / 1024, percentage);
 #if TARGET_OS_TV
-    if (!_playbackStarted) {
         if (percentage >= 10) {
-            _playbackStarted = YES;
             [self performSelectorOnMainThread:@selector(startPlaybackOfPath:) withObject:_filepath waitUntilDone:NO];
         }
-    }
 #endif
 }
 
@@ -593,13 +590,36 @@
 - (void)startPlaybackOfPath:(NSString *)path
 {
     APLog(@"Starting playback of %@", path);
+    if (_receivedFiles == nil)
+        _receivedFiles = [[NSMutableArray alloc] init];
+
+    if ([_receivedFiles containsObject:path])
+        return;
+
+    [_receivedFiles addObject:path];
+
     VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
-    [vpc playURL:[NSURL fileURLWithPath:path] successCallback:nil errorCallback:nil];
+    BOOL needsMediaList;
+    VLCMediaList *mediaList = vpc.mediaList;
+
+    if (!mediaList) {
+        mediaList = [[VLCMediaList alloc] init];
+        needsMediaList = YES;
+    }
+
+    [mediaList addMedia:[VLCMedia mediaWithURL:[NSURL fileURLWithPath:path]]];
 
-    VLCFullscreenMovieTVViewController *moviewVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
-    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:moviewVC
-                                                                                 animated:YES
-                                                                               completion:nil];
+    if (needsMediaList) {
+        [vpc playMediaList:mediaList firstIndex:0];
+    }
+
+    VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
+
+    if (![movieVC isBeingPresented]) {
+        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:movieVC
+                                                                                     animated:YES
+                                                                                   completion:nil];
+    }
 }
 #endif
 
@@ -710,8 +730,13 @@
 - (BOOL)shouldDie
 {
     if (_filepath) {
-        if (_filepath.length > 0)
+        if (_filepath.length > 0) {
             [[VLCHTTPUploaderController sharedInstance] moveFileFrom:_filepath];
+
+#if TARGET_OS_TV
+            [_receivedFiles removeObject:_filepath];
+#endif
+        }
     }
     return [super shouldDie];
 }