Commit 2cca9d0b authored by Felix Paul Kühne's avatar Felix Paul Kühne
Browse files

playback controller: rework media list handling, remove capability to play...

playback controller: rework media list handling, remove capability to play individual files, handle TV show episodes in the playlist way (fixes #14589, #14794, #14800)
parent 19ef22d3
...@@ -25,15 +25,21 @@ ...@@ -25,15 +25,21 @@
[self configureWithAlbumTrack:(MLAlbumTrack *)mediaObject]; [self configureWithAlbumTrack:(MLAlbumTrack *)mediaObject];
} }
else if ([mediaObject isKindOfClass:[MLShowEpisode class]]) else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
[self configureWithSingleFile:[(MLShowEpisode*)mediaObject files].anyObject]; [self configureWithShowEpisode:(MLShowEpisode *)mediaObject];
[self startPlayback]; if (self.activePlaybackSession) {
self.sessionWillRestart = YES;
[self stopPlayback];
} else {
self.sessionWillRestart = NO;
[self startPlayback];
}
} }
- (void)configureWithFile:(MLFile *)file - (void)configureWithFile:(MLFile *)file
{ {
if (file.labels.count == 0) { if (file.labels.count == 0) {
[self configureWithSingleFile:file]; [self configureMediaListWithFiles:@[file] indexToPlay:0];
} else { } else {
MLLabel *folder = [file.labels anyObject]; MLLabel *folder = [file.labels anyObject];
NSArray *files = [folder sortedFolderItems]; NSArray *files = [folder sortedFolderItems];
...@@ -42,10 +48,17 @@ ...@@ -42,10 +48,17 @@
} }
} }
- (void)configureWithSingleFile:(MLFile *)file - (void)configureWithShowEpisode:(MLShowEpisode *)showEpisode
{ {
[file setUnread:@(NO)]; NSArray *episodes = [[showEpisode show] sortedEpisodes];
self.fileFromMediaLibrary = file; NSMutableArray *files = [NSMutableArray arrayWithCapacity:episodes.count];
for (MLShowEpisode *episode in episodes) {
MLFile *file = episode.files.anyObject;
if (files)
[files addObject:file];
}
int index = (int)[episodes indexOfObject:showEpisode];
[self configureMediaListWithFiles:files indexToPlay:index];
} }
- (void)configureWithAlbumTrack:(MLAlbumTrack *)albumTrack - (void)configureWithAlbumTrack:(MLAlbumTrack *)albumTrack
......
...@@ -48,7 +48,8 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -48,7 +48,8 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
@property (nonatomic, strong) UIView *videoOutputView; @property (nonatomic, strong) UIView *videoOutputView;
@property (nonatomic, strong) MLFile *fileFromMediaLibrary; @property (nonatomic, readwrite) BOOL sessionWillRestart;
@property (nonatomic, strong) NSURL *url; @property (nonatomic, strong) NSURL *url;
@property (nonatomic, strong) NSURL *successCallback; @property (nonatomic, strong) NSURL *successCallback;
@property (nonatomic, strong) NSURL *errorCallback; @property (nonatomic, strong) NSURL *errorCallback;
......
...@@ -56,6 +56,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -56,6 +56,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
BOOL _needsMetadataUpdate; BOOL _needsMetadataUpdate;
BOOL _mediaWasJustStarted; BOOL _mediaWasJustStarted;
BOOL _recheckForExistingThumbnail; BOOL _recheckForExistingThumbnail;
BOOL _activeSession;
} }
@end @end
...@@ -107,12 +108,20 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -107,12 +108,20 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
} }
- (BOOL)_isMediaSuitableForDevice - (BOOL)_isMediaSuitableForDevice:(VLCMedia *)media
{ {
if (!self.fileFromMediaLibrary) NSArray *tracksInfo = media.tracksInformation;
return YES; double width, height = 0;
NSDictionary *track;
for (NSUInteger x = 0; x < tracksInfo.count; x++) {
track = tracksInfo[x];
if ([track[VLCMediaTracksInformationType] isEqualToString:VLCMediaTracksInformationTypeVideo]) {
width = [track[VLCMediaTracksInformationVideoWidth] doubleValue];
height = [track[VLCMediaTracksInformationVideoHeight] doubleValue];
}
}
NSUInteger totalNumberOfPixels = [[[self.fileFromMediaLibrary videoTrack] valueForKey:@"width"] doubleValue] * [[[self.fileFromMediaLibrary videoTrack] valueForKey:@"height"] doubleValue]; NSUInteger totalNumberOfPixels = width * height;
NSInteger speedCategory = [[UIDevice currentDevice] speedCategory]; NSInteger speedCategory = [[UIDevice currentDevice] speedCategory];
...@@ -137,6 +146,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -137,6 +146,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
{ {
if (_playerIsSetup) if (_playerIsSetup)
return; return;
_activeSession = YES;
[[AVAudioSession sharedInstance] setDelegate:self]; [[AVAudioSession sharedInstance] setDelegate:self];
...@@ -154,7 +164,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -154,7 +164,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
_aspectRatios = @[@"DEFAULT", @"FILL_TO_SCREEN", @"4:3", @"16:9", @"16:10", @"2.21:1"]; _aspectRatios = @[@"DEFAULT", @"FILL_TO_SCREEN", @"4:3", @"16:9", @"16:10", @"2.21:1"];
if (!self.fileFromMediaLibrary && !self.url && !self.mediaList) { if (!self.url && !self.mediaList) {
[self stopPlayback]; [self stopPlayback];
return; return;
} }
...@@ -183,17 +193,13 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -183,17 +193,13 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
[_mediaPlayer openVideoSubTitlesFromFile:self.pathToExternalSubtitlesFile]; [_mediaPlayer openVideoSubTitlesFromFile:self.pathToExternalSubtitlesFile];
VLCMedia *media; VLCMedia *media;
MLFile *item = self.fileFromMediaLibrary; if (_mediaList) {
if (item) { media = [_mediaList mediaAtIndex:_itemInMediaListToBePlayedFirst];
media = [VLCMedia mediaWithURL:item.url];
media.delegate = self;
} else if (self.mediaList) {
media = [self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst];
media.delegate = self; media.delegate = self;
} else { } else {
media = [VLCMedia mediaWithURL:self.url]; media = [VLCMedia mediaWithURL:self.url];
media.delegate = self; media.delegate = self;
[media parse]; [media synchronousParse];
} }
NSMutableDictionary *mediaDictionary = [[NSMutableDictionary alloc] init]; NSMutableDictionary *mediaDictionary = [[NSMutableDictionary alloc] init];
...@@ -250,9 +256,9 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -250,9 +256,9 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
} }
[_listPlayer setRepeatMode:VLCDoNotRepeat]; [_listPlayer setRepeatMode:VLCDoNotRepeat];
if (![self _isMediaSuitableForDevice]) { if (![self _isMediaSuitableForDevice:media]) {
VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DEVICE_TOOSLOW_TITLE", nil) VLCAlertView *alert = [[VLCAlertView alloc] initWithTitle:NSLocalizedString(@"DEVICE_TOOSLOW_TITLE", nil)
message:[NSString stringWithFormat:NSLocalizedString(@"DEVICE_TOOSLOW", nil), [[UIDevice currentDevice] model], self.fileFromMediaLibrary.title] message:[NSString stringWithFormat:NSLocalizedString(@"DEVICE_TOOSLOW", nil), [[UIDevice currentDevice] model], media.url.lastPathComponent]
delegate:self delegate:self
cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", nil)
otherButtonTitles:NSLocalizedString(@"BUTTON_OPEN", nil), nil]; otherButtonTitles:NSLocalizedString(@"BUTTON_OPEN", nil), nil];
...@@ -263,36 +269,11 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -263,36 +269,11 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
- (void)_playNewMedia - (void)_playNewMedia
{ {
NSNumber *playbackPositionInTime = @(0);
CGFloat lastPosition = .0;
NSInteger duration = 0;
MLFile *matchedFile;
// Set last selected equalizer profile // Set last selected equalizer profile
unsigned int profile = (unsigned int)[[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingEqualizerProfile] integerValue]; unsigned int profile = (unsigned int)[[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingEqualizerProfile] integerValue];
[_mediaPlayer resetEqualizerFromProfile:profile]; [_mediaPlayer resetEqualizerFromProfile:profile];
[_mediaPlayer setPreAmplification:[_mediaPlayer preAmplification]]; [_mediaPlayer setPreAmplification:[_mediaPlayer preAmplification]];
if (self.fileFromMediaLibrary)
matchedFile = self.fileFromMediaLibrary;
else if (self.mediaList) {
NSURL *url = [self.mediaList mediaAtIndex:self.itemInMediaListToBePlayedFirst].url;
NSArray *files = [MLFile fileForURL:url];
matchedFile = files.firstObject;
}
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) {
[_mediaPlayer.media addOptions:@{@"start-time": playbackPositionInTime}];
APLog(@"set starttime to %i", playbackPositionInTime.intValue);
}
[_mediaPlayer addObserver:self forKeyPath:@"time" options:0 context:nil]; [_mediaPlayer addObserver:self forKeyPath:@"time" options:0 context:nil];
[_mediaPlayer addObserver:self forKeyPath:@"remainingTime" options:0 context:nil]; [_mediaPlayer addObserver:self forKeyPath:@"remainingTime" options:0 context:nil];
...@@ -307,10 +288,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -307,10 +288,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
_currentAspectRatioMask = 0; _currentAspectRatioMask = 0;
_mediaPlayer.videoAspectRatio = NULL; _mediaPlayer.videoAspectRatio = NULL;
/* some demuxers don't respect :start-time, so re-try here */
if (lastPosition < .95 && _mediaPlayer.position < lastPosition && (duration * lastPosition - duration) < -60000)
_mediaPlayer.position = lastPosition;
[self subscribeRemoteCommands]; [self subscribeRemoteCommands];
_playerIsSetup = YES; _playerIsSetup = YES;
...@@ -348,8 +325,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -348,8 +325,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
if (_listPlayer) if (_listPlayer)
_listPlayer = nil; _listPlayer = nil;
} }
if (_fileFromMediaLibrary)
_fileFromMediaLibrary = nil;
if (_mediaList) if (_mediaList)
_mediaList = nil; _mediaList = nil;
if (_url) if (_url)
...@@ -369,23 +344,24 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -369,23 +344,24 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil; [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
[self unsubscribeFromRemoteCommand]; [self unsubscribeFromRemoteCommand];
_activeSession = NO;
if (_playbackFailed) { if (_playbackFailed) {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self];
} else { } else if (!_sessionWillRestart) {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self];
} else {
self.sessionWillRestart = NO;
[self startPlayback];
} }
} }
- (void)_savePlaybackState - (void)_savePlaybackState
{ {
MLFile *fileItem = self.fileFromMediaLibrary; MLFile *fileItem;
NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url];
if (!fileItem) { if (files.count > 0)
NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url]; fileItem = files.firstObject;
if (files.count > 0)
fileItem = files.firstObject;
}
if (!fileItem) if (!fileItem)
return; return;
...@@ -492,7 +468,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -492,7 +468,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
- (BOOL)activePlaybackSession - (BOOL)activePlaybackSession
{ {
return _mediaPlayer != nil; return _activeSession;
} }
- (BOOL)audioOnlyPlaybackSession - (BOOL)audioOnlyPlaybackSession
...@@ -746,13 +722,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -746,13 +722,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
#pragma mark - Managing the media item #pragma mark - Managing the media item
- (void)setFileFromMediaLibrary:(MLFile *)fileFromMediaLibrary
{
[self stopPlayback];
_fileFromMediaLibrary = fileFromMediaLibrary;
_playerIsSetup = NO;
}
- (void)setUrl:(NSURL *)url - (void)setUrl:(NSURL *)url
{ {
[self stopPlayback]; [self stopPlayback];
...@@ -768,10 +737,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -768,10 +737,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
} }
- (MLFile *)currentlyPlayingMediaFile { - (MLFile *)currentlyPlayingMediaFile {
MLFile *mediaFile = self.fileFromMediaLibrary; if (self.mediaList) {
if (mediaFile) {
return mediaFile;
} else if (self.mediaList) {
NSArray *results = [MLFile fileForURL:_mediaPlayer.media.url]; NSArray *results = [MLFile fileForURL:_mediaPlayer.media.url];
return results.firstObject; return results.firstObject;
} }
...@@ -813,9 +779,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -813,9 +779,7 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
UIImage* artworkImage; UIImage* artworkImage;
BOOL mediaIsAudioOnly = NO; BOOL mediaIsAudioOnly = NO;
if (self.fileFromMediaLibrary) if (self.mediaList) {
item = self.fileFromMediaLibrary;
else if (self.mediaList) {
NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url]; NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url];
item = matches.firstObject; item = matches.firstObject;
} }
...@@ -880,6 +844,16 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl ...@@ -880,6 +844,16 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
if (item.lastSubtitleTrack.intValue > 0) if (item.lastSubtitleTrack.intValue > 0)
_mediaPlayer.currentVideoSubTitleIndex = item.lastSubtitleTrack.intValue; _mediaPlayer.currentVideoSubTitleIndex = item.lastSubtitleTrack.intValue;
} }
CGFloat lastPosition = .0;
NSInteger duration = 0;
if (item.lastPosition)
lastPosition = item.lastPosition.floatValue;
duration = item.duration.intValue;
if (lastPosition < .95 && _mediaPlayer.position < lastPosition && (duration * lastPosition - duration) < -60000)
_mediaPlayer.position = lastPosition;
} }
} }
......
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