Browse Source

Remote Playback: automatically start playing once we cached at least 10% of the announced file size

Felix Paul Kühne 9 years ago
parent
commit
e7d2299ae2

+ 22 - 1
Sources/VLCHTTPConnection.m

@@ -36,6 +36,9 @@
     NSString *_filepath;
     UInt64 _contentLength;
     UInt64 _receivedContent;
+#if TARGET_OS_TV
+    BOOL _playbackStarted;
+#endif
 }
 @end
 
@@ -424,7 +427,25 @@
 
     _receivedContent += postDataChunk.length;
 
-    APLog(@"received %lli kB (%lli %%)", _receivedContent / 1024, ((_receivedContent * 100) / _contentLength));
+    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;
+
+            APLog(@"Starting playback of %@", _filepath);
+            VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+            [vpc playURL:[NSURL fileURLWithPath:_filepath] successCallback:nil errorCallback:nil];
+
+            VLCFullscreenMovieTVViewController *moviewVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
+            [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:moviewVC
+                                                                                         animated:YES
+                                                                                       completion:nil];
+
+        }
+    }
+#endif
 }
 
 //-----------------------------------------------------------------

+ 6 - 5
Sources/VLCHTTPUploaderController.m

@@ -225,6 +225,12 @@
 
 - (void)moveFileFrom:(NSString *)filepath
 {
+    /* update media library when file upload was completed */
+    VLCActivityManager *activityManager = [VLCActivityManager defaultManager];
+    [activityManager networkActivityStopped];
+    [activityManager activateIdleTimer];
+
+#if TARGET_OS_IOS
     NSString *fileName = [filepath lastPathComponent];
     NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *libraryPath = searchPaths[0];
@@ -251,11 +257,6 @@
         [fileManager removeItemAtPath:filepath error:nil];
     }
 
-    /* update media library when file upload was completed */
-    VLCActivityManager *activityManager = [VLCActivityManager defaultManager];
-    [activityManager networkActivityStopped];
-    [activityManager activateIdleTimer];
-#if TARGET_OS_IOS
     [[VLCMediaFileDiscoverer sharedInstance] performSelectorOnMainThread:@selector(updateMediaList) withObject:nil waitUntilDone:NO];
 #endif
 }

+ 7 - 0
VLC for Apple TV/Playback/VLCFullscreenMovieTVViewController.m

@@ -13,6 +13,7 @@
 #import "VLCPlaybackInfoTVViewController.h"
 #import "VLCPlaybackInfoTVAnimators.h"
 #import "VLCIRTVTapGestureRecognizer.h"
+#import "VLCHTTPUploaderController.h"
 
 typedef NS_ENUM(NSInteger, VLCPlayerScanState)
 {
@@ -139,6 +140,12 @@ typedef NS_ENUM(NSInteger, VLCPlayerScanState)
     [vpc stopPlayback];
 
     [super viewWillDisappear:animated];
+
+    /* clean caches in case remote playback was used
+     * note that if we cancel before the upload is complete
+     * the cache won't be emptied, but on the next launch only (or if the system is under storage pressure)
+     */
+    [[VLCHTTPUploaderController sharedInstance] cleanCache];
 }
 
 - (BOOL)canBecomeFirstResponder