Forráskód Böngészése

VLCPlaybackService: Fix background Chromecast playback

Before, the application could get "killed" by the system when the user
backgrounded while chromecasting.

We use a dummy media player in order to play silence via /dev/zero.

Since there is no notion of services on iOS, this is a workaround so
that the system let us chromecasting.

Closes #648
Soomin Lee 5 éve
szülő
commit
94fe21e0c9
1 módosított fájl, 14 hozzáadás és 0 törlés
  1. 14 0
      Sources/VLCPlaybackService.m

+ 14 - 0
Sources/VLCPlaybackService.m

@@ -36,6 +36,7 @@ NSString *const VLCPlaybackServicePlaybackPositionUpdated = @"VLCPlaybackService
 @interface VLCPlaybackService () <VLCMediaPlayerDelegate, VLCMediaDelegate, VLCRemoteControlServiceDelegate>
 {
     VLCRemoteControlService *_remoteControlService;
+    VLCMediaPlayer *_backgroundDummyPlayer;
     VLCMediaPlayer *_mediaPlayer;
     VLCMediaListPlayer *_listPlayer;
     BOOL _shouldResumePlaying;
@@ -123,6 +124,11 @@ NSString *const VLCPlaybackServicePlaybackPositionUpdated = @"VLCPlaybackService
         _playbackSessionManagementLock = [[NSLock alloc] init];
         _shuffleMode = NO;
         _shuffleStack = [[NSMutableArray alloc] init];
+
+        // Initialize a separate media player in order to play silence so that the application can
+        // stay alive in background exclusively for Chromecast.
+        _backgroundDummyPlayer = [[VLCMediaPlayer alloc] initWithOptions:@[@"--demux=rawaud"]];
+        _backgroundDummyPlayer.media = [[VLCMedia alloc] initWithPath:@"/dev/zero"];
     }
     return self;
 }
@@ -1211,6 +1217,10 @@ NSString *const VLCPlaybackServicePlaybackPositionUpdated = @"VLCPlaybackService
 
     if (!_renderer && _mediaPlayer.audioTrackIndexes.count > 0)
         [self setVideoTrackEnabled:false];
+
+    if (_renderer) {
+        [_backgroundDummyPlayer play];
+    }
 }
 
 - (void)applicationDidBecomeActive:(NSNotification *)notification
@@ -1220,6 +1230,10 @@ NSString *const VLCPlaybackServicePlaybackPositionUpdated = @"VLCPlaybackService
         _preBackgroundWrapperView = nil;
     }
 
+    if (_renderer) {
+        [_backgroundDummyPlayer stop];
+    }
+
     [self setVideoTrackEnabled:true];
 
     if (_shouldResumePlaying) {