Commit 26264da5 authored by Carola Nitz's avatar Carola Nitz

VLCPlaybackController : remove playURL calls and use medialist instead everywhere

parent 0f8bdb39
Pipeline #217 failed with stage
in 0 seconds
......@@ -143,7 +143,11 @@
- (void)_openURLStringAndDismiss:(NSString *)urlString
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:[NSURL URLWithString:urlString] subtitlesFilePath:nil];
VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:urlString]];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
[self presentViewController:[VLCFullscreenMovieTVViewController fullscreenMovieTVViewController]
animated:YES
completion:nil];
......
......@@ -268,12 +268,15 @@
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
NSURL *url;
@synchronized(_discoveredFiles) {
url = [NSURL fileURLWithPath:_discoveredFiles[indexPath.row]];
}
[vpc playURL:url subtitlesFilePath:nil];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:url]];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
[self presentViewController:[VLCFullscreenMovieTVViewController fullscreenMovieTVViewController]
animated:YES
completion:nil];
......
......@@ -182,12 +182,14 @@
NSURL *url = service.directPlaybackURL;
if (!url) return;
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:url subtitlesFilePath:nil];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:url]];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
[self presentViewController:[VLCFullscreenMovieTVViewController fullscreenMovieTVViewController]
animated:YES
completion:nil];
return;
}
}
......
......@@ -164,8 +164,9 @@
[connection cancel];
/* now ask VLC to stream the URL we were just passed */
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:theActualURL successCallback:nil errorCallback:nil];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:theActualURL]];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
[self presentViewController:movieVC
......
......@@ -96,8 +96,11 @@
} else {
/* stream file */
NSURL *url = [NSURL URLWithString:selectedObject.downloadPath];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:url successCallback:nil errorCallback:nil];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:url]];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
[self presentViewController:movieVC
animated:YES
......
......@@ -201,8 +201,7 @@
- (void)streamMediaList:(VLCMediaList *)mediaList startingAtIndex:(NSInteger)startIndex
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playMediaList:mediaList firstIndex:startIndex];
[[VLCPlaybackController sharedInstance] playMediaList:mediaList firstIndex:startIndex subtitlesFilePath:nil];
[self showMovieViewController];
}
......@@ -221,10 +220,10 @@
if(remoteSubtitleURL)
URLofSubtitle = [self _getFileSubtitleFromServer:remoteSubtitleURL];
NSURL *URLToPlay = item.URL;
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:URLToPlay subtitlesFilePath:URLofSubtitle];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:item.URL]];
[vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:URLofSubtitle];
[self showMovieViewController];
}
......
......@@ -358,7 +358,7 @@
[mediaList addMedia:[VLCMedia mediaWithURL:[NSURL URLWithString:urlString]]];
if (needsMediaList) {
[vpc playMediaList:mediaList firstIndex:0];
[vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil];
VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
if ([[[UIApplication sharedApplication].delegate.window rootViewController] presentedViewController] != nil) {
......
......@@ -189,8 +189,10 @@
if ([service respondsToSelector:@selector(directPlaybackURL)]) {
NSURL *playbackURL = [service directPlaybackURL];
if (playbackURL) {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:playbackURL successCallback:nil errorCallback:nil];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:playbackURL]];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
return;
}
}
......
......@@ -340,7 +340,13 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
if ([action isEqualToString:@"stream"] && movieURL) {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.fullscreenSessionRequested = YES;
[vpc playURL:movieURL successCallback:successCallback errorCallback:errorCallback];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:movieURL]];
vpc.successCallback = successCallback;
vpc.errorCallback = errorCallback;
[vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
}
else if ([action isEqualToString:@"download"] && movieURL) {
[self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
......@@ -375,15 +381,19 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
if (cancelled)
[self downloadMovieFromURL:url fileNameOfMedia:nil];
else {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:url successCallback:nil errorCallback:nil];
VLCMedia *media = [VLCMedia mediaWithURL:url];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
}
};
[alert show];
} else {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.fullscreenSessionRequested = YES;
[vpc playURL:url successCallback:nil errorCallback:nil];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:[VLCMedia mediaWithURL:url]];
[vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
}
}
return YES;
......
......@@ -221,7 +221,10 @@
/* now ask VLC to stream the URL we were just passed */
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:theActualURL successCallback:nil errorCallback:nil];
VLCMedia *media = [VLCMedia mediaWithURL:theActualURL];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
}
return request;
......
......@@ -269,8 +269,10 @@
[[_client.filesRoutes getTemporaryLink:path] setResponseBlock:^(DBFILESGetTemporaryLinkResult * _Nullable result, DBFILESGetTemporaryLinkError * _Nullable routeError, DBRequestError * _Nullable networkError) {
if (result) {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:[NSURL URLWithString:result.link ] successCallback:nil errorCallback:nil];
VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:result.link]];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
#if TARGET_OS_TV
if (_lastKnownNavigationController) {
VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
......
......@@ -219,7 +219,10 @@
file.identifier, token];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:[NSURL URLWithString:urlString] successCallback:nil errorCallback:nil];
VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:urlString]];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[vpc playMediaList:medialist firstIndex:0 subtitlesFilePath:nil];
}
- (void)_triggerNextDownload
......
......@@ -646,18 +646,16 @@
[_receivedFiles addObject:path];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
BOOL needsMediaList;
VLCMediaList *mediaList = vpc.mediaList;
if (!mediaList) {
mediaList = [[VLCMediaList alloc] init];
needsMediaList = YES;
}
[mediaList addMedia:[VLCMedia mediaWithURL:[NSURL fileURLWithPath:path]]];
if (needsMediaList) {
[vpc playMediaList:mediaList firstIndex:0];
if (!vpc.mediaList) {
[vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil];
}
VLCFullscreenMovieTVViewController *movieVC = [VLCFullscreenMovieTVViewController fullscreenMovieTVViewController];
......
......@@ -113,7 +113,10 @@
NSString *subtitlePath = [self _searchSubtitle:selectedObject.name];
subtitlePath = [self _getFileSubtitleFromServer:[NSURL URLWithString:subtitlePath]];
NSURL *url = [NSURL URLWithString:selectedObject.downloadPath];
[vpc playURL:url subtitlesFilePath:subtitlePath];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia: [VLCMedia mediaWithURL:url]];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:subtitlePath];
} else {
NSUInteger count = folderItems.count;
NSMutableArray *mediaItems = [[NSMutableArray alloc] init];
......@@ -135,7 +138,7 @@
if (mediaItems.count > 0) {
firstIndex = mediaItems.count - posIndex;
[vpc playMediaList:[[VLCMediaList alloc] initWithArray:mediaItems] firstIndex:firstIndex];
[vpc playMediaList:[[VLCMediaList alloc] initWithArray:mediaItems] firstIndex:firstIndex subtitlesFilePath:nil];
}
}
}
......@@ -211,7 +214,7 @@
}
if (mediaItems.count > 0) {
[vpc playMediaList:[[VLCMediaList alloc] initWithArray:mediaItems] firstIndex:0];
[vpc playMediaList:[[VLCMediaList alloc] initWithArray:mediaItems] firstIndex:0 subtitlesFilePath:nil];
}
}
......
......@@ -359,8 +359,10 @@ forRowAtIndexPath:(NSIndexPath *)indexPath
URLofSubtitle = [self _checkURLofSubtitle:url];
}
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playURL:[NSURL URLWithString:url] subtitlesFilePath:URLofSubtitle];
VLCMedia *media = [VLCMedia mediaWithURL:[NSURL URLWithString:url]];
VLCMediaList *medialist = [[VLCMediaList alloc] init];
[medialist addMedia:media];
[[VLCPlaybackController sharedInstance] playMediaList:medialist firstIndex:0 subtitlesFilePath:URLofSubtitle];
}
- (NSString *)_checkURLofSubtitle:(NSString *)url
......
......@@ -132,8 +132,7 @@ Open a file in the libraryViewController without changing the playstate
- (void)configureMediaList:(VLCMediaList *)list atIndex:(int)index
{
self.pathToExternalSubtitlesFile = nil;
[self playMediaList:list firstIndex:index];
[self playMediaList:list firstIndex:index subtitlesFilePath:nil];
}
@end
......@@ -47,7 +47,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
@property (nonatomic, readwrite) BOOL sessionWillRestart;
@property (nonatomic, strong) NSURL *url;
@property (nonatomic, strong) NSURL *successCallback;
@property (nonatomic, strong) NSURL *errorCallback;
......@@ -96,8 +95,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
- (void)setNeedsMetadataUpdate;
- (void)scheduleSleepTimerWithInterval:(NSTimeInterval)timeInterval;
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index;
- (void)playURL:(NSURL *)url successCallback:(NSURL*)successCallback errorCallback:(NSURL *)errorCallback;
- (void)playURL:(NSURL *)url subtitlesFilePath:(NSString *)subsFilePath;
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString *)subsFilePath;
@end
......@@ -17,7 +17,6 @@
*****************************************************************************/
#import "VLCPlaybackController.h"
#import <CommonCrypto/CommonDigest.h>
#import "UIDevice+VLC.h"
#import <AVFoundation/AVFoundation.h>
#import "VLCPlayerDisplayController.h"
......@@ -101,10 +100,13 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
{
self = [super init];
if (self) {
// listen to audiosessions and appkit callback
_headphonesWasPlugged = [self areHeadphonesPlugged];
NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
name:AVAudioSessionRouteChangeNotification object:nil];
// appkit because we neeed to know when we go to background in order to stop the video, so that we don't crash
[defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
[defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:)
......@@ -132,50 +134,14 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
}
#pragma mark - playback management
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString *)subsFilePath
{
self.mediaList = mediaList;
self.itemInMediaListToBePlayedFirst = (int)index;
self.pathToExternalSubtitlesFile = nil;
if (self.activePlaybackSession) {
self.sessionWillRestart = YES;
[self stopPlayback];
} else {
self.sessionWillRestart = NO;
[self startPlayback];
}
}
- (void)playURL:(NSURL *)url successCallback:(NSURL*)successCallback errorCallback:(NSURL *)errorCallback
{
self.url = url;
self.successCallback = successCallback;
self.errorCallback = errorCallback;
if (self.activePlaybackSession) {
self.sessionWillRestart = YES;
[self stopPlayback];
} else {
self.sessionWillRestart = NO;
[self startPlayback];
}
}
- (void)playURL:(NSURL *)url subtitlesFilePath:(NSString *)subsFilePath
{
self.url = url;
self.pathToExternalSubtitlesFile = subsFilePath;
if (self.activePlaybackSession) {
self.sessionWillRestart = YES;
[self stopPlayback];
} else {
self.sessionWillRestart = NO;
dispatch_async(dispatch_get_main_queue(), ^{
[self startPlayback];
});
}
self.sessionWillRestart = self.activePlaybackSession;
self.activePlaybackSession ? [self stopPlayback] : [self startPlayback];
}
- (void)startPlayback
......@@ -199,7 +165,7 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (!self.url && !self.mediaList) {
if (!self.mediaList) {
APLog(@"%s: no URL and no media list set, stopping playback", __PRETTY_FUNCTION__);
[_playbackSessionManagementLock unlock];
[self stopPlayback];
......@@ -234,23 +200,13 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
if (self.pathToExternalSubtitlesFile)
[_mediaPlayer addPlaybackSlave:[NSURL fileURLWithPath:self.pathToExternalSubtitlesFile] type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES];
VLCMedia *media;
if (_mediaList) {
media = [_mediaList mediaAtIndex:_itemInMediaListToBePlayedFirst];
[media parseWithOptions:VLCMediaParseLocal];
media.delegate = self;
} else {
media = [VLCMedia mediaWithURL:self.url];
media.delegate = self;
[media parseWithOptions:VLCMediaParseLocal];
[media addOptions:self.mediaOptionsDictionary];
}
VLCMedia *media = [_mediaList mediaAtIndex:_itemInMediaListToBePlayedFirst];
[media parseWithOptions:VLCMediaParseLocal];
media.delegate = self;
[media addOptions:self.mediaOptionsDictionary];
[_listPlayer setMediaList:self.mediaList];
if (self.mediaList) {
[_listPlayer setMediaList:self.mediaList];
} else {
[_listPlayer setRootMedia:media];
}
[_listPlayer setRepeatMode:VLCDoNotRepeat];
[_playbackSessionManagementLock unlock];
......@@ -276,10 +232,7 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
[_mediaPlayer addObserver:self forKeyPath:@"time" options:0 context:nil];
[_mediaPlayer addObserver:self forKeyPath:@"remainingTime" options:0 context:nil];
if (self.mediaList)
[_listPlayer playItemAtNumber:@(self.itemInMediaListToBePlayedFirst)];
else
[_listPlayer playMedia:_listPlayer.rootMedia];
[_listPlayer playItemAtNumber:@(self.itemInMediaListToBePlayedFirst)];
if ([self.delegate respondsToSelector:@selector(prepareForMediaPlayback:)])
[self.delegate prepareForMediaPlayback:self];
......@@ -320,16 +273,11 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
#endif
[_mediaPlayer stop];
}
if (_mediaPlayer)
_mediaPlayer = nil;
if (_listPlayer)
_listPlayer = nil;
_mediaPlayer = nil;
_listPlayer = nil;
}
if (!_sessionWillRestart) {
if (_mediaList)
_mediaList = nil;
if (_url)
_url = nil;
_mediaList = nil;
if (_pathToExternalSubtitlesFile) {
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:_pathToExternalSubtitlesFile])
......@@ -340,10 +288,10 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
_playerIsSetup = NO;
[_shuffleStack removeAllObjects];
if (self.errorCallback && _playbackFailed && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:self.errorCallback];
else if (self.successCallback && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:self.successCallback];
if (_errorCallback && _playbackFailed && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:_errorCallback];
else if (_successCallback && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:_successCallback];
[[self remoteControlService] unsubscribeFromRemoteCommands];
_activeSession = NO;
......@@ -369,10 +317,8 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
APLog(@"saving playback state failed");
}
MLFile *fileItem;
NSArray *files = [MLFile fileForURL:_mediaPlayer.media.url];
if (files.count > 0)
fileItem = files.firstObject;
MLFile *fileItem = files.firstObject;
if (!fileItem) {
APLog(@"couldn't find file, not saving playback progress");
......@@ -449,9 +395,8 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
_mediaWasJustStarted = NO;
#if TARGET_OS_IOS
if (self.mediaList) {
MLFile *item;
NSArray *matches = [MLFile fileForURL:_mediaPlayer.media.url];
item = matches.firstObject;
MLFile *item = matches.firstObject;
[self _recoverLastPlaybackStateOfItem:item];
}
#else
......
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