Commit 3cdd12f2 authored by Felix Paul Kühne's avatar Felix Paul Kühne

playback: fix playback position handling for media lists of locally stored content

parent fe6c247c
......@@ -416,7 +416,10 @@
if (self.fileFromMediaLibrary) {
MLFile *item = self.fileFromMediaLibrary;
media = [VLCMedia mediaWithURL:[NSURL URLWithString:item.url]];
} else if (!self.mediaList) {
} else if (self.mediaList) {
media = [self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst];
[media parse];
} else {
media = [VLCMedia mediaWithURL:self.url];
[media parse];
}
......@@ -526,16 +529,26 @@
{
NSNumber *playbackPositionInTime = @(0);
CGFloat lastPosition = .0;
NSInteger duration = self.fileFromMediaLibrary.duration.intValue;
if (self.fileFromMediaLibrary.lastPosition)
lastPosition = self.fileFromMediaLibrary.lastPosition.floatValue;
NSInteger duration = 0;
MLFile *matchedFile;
if (self.fileFromMediaLibrary)
matchedFile = self.fileFromMediaLibrary;
else if (self.mediaList) {
NSArray *matches = [MLFile fileForURL:[[[self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst] url] absoluteString]];
if (matches.count > 0) {
matchedFile = matches[0];
lastPosition = matchedFile.lastPosition.floatValue;
}
}
if (matchedFile.lastPosition)
lastPosition = matchedFile.lastPosition.floatValue;
duration = matchedFile.duration.intValue;
if (lastPosition < .95) {
if (duration != 0)
playbackPositionInTime = @(lastPosition * (duration / 1000.));
}
if (playbackPositionInTime.intValue > 0 && (duration * lastPosition - duration) < -60000) {
/* start time is not supported for media lists */
[_mediaPlayer.media addOptions:@{@"start-time": playbackPositionInTime}];
APLog(@"set starttime to %i", playbackPositionInTime.intValue);
}
......@@ -548,11 +561,11 @@
else
[_listPlayer playMedia:_listPlayer.rootMedia];
if (self.fileFromMediaLibrary) {
if (self.fileFromMediaLibrary.lastAudioTrack.intValue > 0)
_mediaPlayer.currentAudioTrackIndex = self.fileFromMediaLibrary.lastAudioTrack.intValue;
if (self.fileFromMediaLibrary.lastSubtitleTrack.intValue > 0)
_mediaPlayer.currentVideoSubTitleIndex = self.fileFromMediaLibrary.lastSubtitleTrack.intValue;
if (matchedFile) {
if (matchedFile.lastAudioTrack.intValue > 0)
_mediaPlayer.currentAudioTrackIndex = matchedFile.lastAudioTrack.intValue;
if (matchedFile.lastSubtitleTrack.intValue > 0)
_mediaPlayer.currentVideoSubTitleIndex = matchedFile.lastSubtitleTrack.intValue;
}
self.playbackSpeedSlider.value = [self _playbackSpeed];
......@@ -634,6 +647,14 @@
@catch (NSException *exception) {
APLog(@"failed to save current media state - file removed?");
}
} else {
NSArray *files = [MLFile fileForURL:[[_mediaPlayer.media url] absoluteString]];
if (files.count > 0) {
MLFile *fileFromList = files[0];
fileFromList.lastPosition = @([_mediaPlayer position]);
fileFromList.lastAudioTrack = @(_mediaPlayer.currentAudioTrackIndex);
fileFromList.lastSubtitleTrack = @(_mediaPlayer.currentVideoSubTitleIndex);
}
}
}
......@@ -943,7 +964,8 @@
}
if ((currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) && _listPlayer.repeatMode == VLCDoNotRepeat) {
if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == _listPlayer.mediaList.count - 1)[self performSelector:@selector(closePlayback:) withObject:nil afterDelay:2.];
if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == _listPlayer.mediaList.count - 1)
[self performSelector:@selector(closePlayback:) withObject:nil afterDelay:2.];
}
UIImage *playPauseImage = [_mediaPlayer isPlaying]? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
......
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