Commit 8a18c576 authored by Soomin Lee's avatar Soomin Lee Committed by Carola

VLCPlaybackController: Fix restoration of audio and subtitle track(closes #19351)

The restoration needs to be done on libvlc's `ESAdded` event.
Signed-off-by: Carola's avatarCarola Nitz <nitz.carola@googlemail.com>
parent 62293888
...@@ -706,36 +706,52 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) { ...@@ -706,36 +706,52 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
{ {
VLCMediaPlayerState currentState = _mediaPlayer.state; VLCMediaPlayerState currentState = _mediaPlayer.state;
if (currentState == VLCMediaPlayerStateBuffering) { switch (currentState) {
/* attach delegate */ case VLCMediaPlayerStateBuffering: {
_mediaPlayer.media.delegate = self; /* attach delegate */
_mediaPlayer.media.delegate = self;
/* on-the-fly values through hidden API */
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; /* on-the-fly values through hidden API */
[_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFont]]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[_mediaPlayer performSelector:@selector(setTextRendererFontSize:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontSize]]; [_mediaPlayer performSelector:@selector(setTextRendererFont:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFont]];
[_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontColor]]; [_mediaPlayer performSelector:@selector(setTextRendererFontSize:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontSize]];
[_mediaPlayer performSelector:@selector(setTextRendererFontForceBold:) withObject:[defaults objectForKey:kVLCSettingSubtitlesBoldFont]]; [_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[defaults objectForKey:kVLCSettingSubtitlesFontColor]];
} else if (currentState == VLCMediaPlayerStateError) { [_mediaPlayer performSelector:@selector(setTextRendererFontForceBold:) withObject:[defaults objectForKey:kVLCSettingSubtitlesBoldFont]];
APLog(@"Playback failed"); } break;
dispatch_async(dispatch_get_main_queue(),^{
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self]; case VLCMediaPlayerStateError: {
}); APLog(@"Playback failed");
_sessionWillRestart = NO; dispatch_async(dispatch_get_main_queue(),^{
[self stopPlayback]; [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self];
} 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; } break;
} 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];
} break;
case VLCMediaPlayerStateESAdded: {
MLFile *item = [MLFile fileForURL:_mediaPlayer.media.url].firstObject;
if (item) {
_mediaPlayer.currentAudioTrackIndex = item.lastAudioTrack.intValue;
_mediaPlayer.currentVideoSubTitleIndex = item.lastSubtitleTrack.intValue;
}
} break;
default:
break;
} }
if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)]) if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)])
...@@ -1079,15 +1095,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) { ...@@ -1079,15 +1095,6 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
- (void)_recoverLastPlaybackStateOfItem:(MLFile *)item - (void)_recoverLastPlaybackStateOfItem:(MLFile *)item
{ {
if (item) { if (item) {
if (_mediaPlayer.numberOfAudioTracks > 2) {
if (item.lastAudioTrack.intValue > 0)
_mediaPlayer.currentAudioTrackIndex = item.lastAudioTrack.intValue;
}
if (_mediaPlayer.numberOfSubtitlesTracks > 2) {
if (item.lastSubtitleTrack.intValue > 0)
_mediaPlayer.currentVideoSubTitleIndex = item.lastSubtitleTrack.intValue;
}
CGFloat lastPosition = .0; CGFloat lastPosition = .0;
NSInteger duration = 0; NSInteger duration = 0;
......
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