Commit 94fe21e0 authored by Soomin Lee's avatar Soomin Lee

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
parent 4e6181d1
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment