Commit f9867ab3 authored by Carola's avatar Carola

VLCPlaybackController:send notifications about playback state change when...

VLCPlaybackController:send notifications about playback state change when libvlc actually changed it

The notifications were sent too early which caused a wrong determination of isPlaying state in the VLCPlayerDisplayController who observed these
This led to a bug where media was actually playing but there were no controls to actually pause or stop the playback
parent 7bfd54b8
...@@ -251,7 +251,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) { ...@@ -251,7 +251,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
_playerIsSetup = YES; _playerIsSetup = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStart object:self];
[_playbackSessionManagementLock unlock]; [_playbackSessionManagementLock unlock];
} }
...@@ -302,9 +301,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) { ...@@ -302,9 +301,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
[[self remoteControlService] unsubscribeFromRemoteCommands]; [[self remoteControlService] unsubscribeFromRemoteCommands];
[_playbackSessionManagementLock unlock]; [_playbackSessionManagementLock unlock];
if (!_sessionWillRestart) { if (_sessionWillRestart) {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self];
} else {
_sessionWillRestart = NO; _sessionWillRestart = NO;
[self startPlayback]; [self startPlayback];
} }
...@@ -704,42 +701,57 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) { ...@@ -704,42 +701,57 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
- (void)mediaPlayerStateChanged:(NSNotification *)aNotification - (void)mediaPlayerStateChanged:(NSNotification *)aNotification
{ {
VLCMediaPlayerState currentState = _mediaPlayer.state; switch (_mediaPlayer.state) {
case VLCMediaPlayerStateBuffering: {
if (currentState == VLCMediaPlayerStateBuffering) { _mediaPlayer.media.delegate = self;
/* attach delegate */
_mediaPlayer.media.delegate = self;
/* on-the-fly values through hidden API */ /* on-the-fly values through hidden API */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFont]]; [_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFont]];
[_mediaPlayer performSelector:@selector(setTextRendererFontSize:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontSize]]; [_mediaPlayer performSelector:@selector(setTextRendererFontSize:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontSize]];
[_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontColor]]; [_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontColor]];
[_mediaPlayer performSelector:@selector(setTextRendererFontForceBold:) withObject:[defaults objectForKey:kVLCSettingSubtitlesBoldFont]]; [_mediaPlayer performSelector:@selector(setTextRendererFontForceBold:) withObject:[defaults objectForKey:kVLCSettingSubtitlesBoldFont]];
} else if (currentState == VLCMediaPlayerStateError) { break;
APLog(@"Playback failed"); }
dispatch_async(dispatch_get_main_queue(),^{ case VLCMediaPlayerStateError: {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self]; APLog(@"Playback failed");
}); dispatch_async(dispatch_get_main_queue(),^{
_sessionWillRestart = NO; [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self];
[self stopPlayback]; });
} else if (currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) {
[_listPlayer.mediaList lock];
NSUInteger listCount = _listPlayer.mediaList.count;
if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == listCount - 1 && self.repeatMode == VLCDoNotRepeat) {
[_listPlayer.mediaList unlock];
_sessionWillRestart = NO; _sessionWillRestart = NO;
[self stopPlayback]; [self stopPlayback];
return; }
} else if (listCount > 1) { case VLCMediaPlayerStateEnded:
[_listPlayer.mediaList unlock]; case VLCMediaPlayerStateStopped: {
[_listPlayer next]; [_listPlayer.mediaList lock];
} else NSUInteger listCount = _listPlayer.mediaList.count;
[_listPlayer.mediaList unlock]; if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == listCount - 1 && self.repeatMode == VLCDoNotRepeat) {
} [_listPlayer.mediaList unlock];
_sessionWillRestart = NO;
[self stopPlayback];
return;
} else if (listCount > 1) {
[_listPlayer.mediaList unlock];
[_listPlayer next];
} else
[_listPlayer.mediaList unlock];
dispatch_async(dispatch_get_main_queue(),^{
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self];
});
} break;
case VLCMediaPlayerStatePlaying: {
dispatch_async(dispatch_get_main_queue(),^{
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStart object:self];
});
break;
}
case VLCMediaPlayerStateOpening:
case VLCMediaPlayerStatePaused:
break;
}
if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)]) if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)])
[self.delegate mediaPlayerStateChanged:currentState [self.delegate mediaPlayerStateChanged:_mediaPlayer.state
isPlaying:_mediaPlayer.isPlaying isPlaying:_mediaPlayer.isPlaying
currentMediaHasTrackToChooseFrom:self.currentMediaHasTrackToChooseFrom currentMediaHasTrackToChooseFrom:self.currentMediaHasTrackToChooseFrom
currentMediaHasChapters:self.currentMediaHasChapters currentMediaHasChapters:self.currentMediaHasChapters
......
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