Commit 69bdb206 authored by Carola Nitz's avatar Carola Nitz

VLCPlaybackController: Add playbackCompletionBlock to remove explicit url knowledge

Instead of handling the url success and error callbacks in the playbackViewcontroller
they should be done whereever the call came from
parent d5fcf4a2
......@@ -326,7 +326,7 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
NSURLRelationship relationship;
[manager getRelationship:&relationship ofDirectoryAtURL:[NSURL fileURLWithPath:directoryPath] toItemAtURL:url error:&theError];
if (relationship == NSURLRelationshipContains) {
[self playWithURL:url successCallback:nil errorCallback:nil];
[self playWithURL:url completion:nil];
}
} else if ([url.scheme isEqualToString:@"vlc-x-callback"] || [url.host isEqualToString:@"x-callback-url"]) {
// URL confirmes to the x-callback-url specification
......@@ -353,7 +353,18 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
errorCallback = [NSURL URLWithString:value];
}
if ([action isEqualToString:@"stream"] && movieURL) {
[self playWithURL:movieURL successCallback:successCallback errorCallback:errorCallback];
[self playWithURL:movieURL completion:^(BOOL success) {
NSURL *callback = success ? successCallback : errorCallback;
if (@available(iOS 10, *)) {
[[UIApplication sharedApplication] openURL:callback options:@{} completionHandler:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
/* UIApplication's replacement calls require iOS 10 or later, which we can't enforce as of yet */
[[UIApplication sharedApplication] openURL:callback];
#pragma clang diagnostic pop
}
}];
}
else if ([action isEqualToString:@"download"] && movieURL) {
[self downloadMovieFromURL:movieURL fileNameOfMedia:fileName];
......@@ -388,12 +399,12 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
if (cancelled)
[self downloadMovieFromURL:url fileNameOfMedia:nil];
else {
[self playWithURL:url successCallback:nil errorCallback:nil];
[self playWithURL:url completion:nil];
}
};
[alert show];
} else {
[self playWithURL:url successCallback:nil errorCallback:nil];
[self playWithURL:url completion:nil];
}
}
return YES;
......@@ -500,14 +511,12 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
}
#pragma mark - playback
- (void)playWithURL:(NSURL *)url successCallback:(NSURL *)successCallback errorCallback:(NSURL *)errorCallback
- (void)playWithURL:(NSURL *)url completion:(void (^ __nullable)(BOOL success))completion
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.fullscreenSessionRequested = YES;
vpc.successCallback = successCallback;
vpc.errorCallback = errorCallback;
VLCMediaList *mediaList = [[VLCMediaList alloc] initWithArray:@[[VLCMedia mediaWithURL:url]]];
[vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil];
[vpc playMediaList:mediaList firstIndex:0 subtitlesFilePath:nil completion:completion];
}
#pragma mark - watch stuff
......
......@@ -43,9 +43,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
@property (nonatomic, strong) UIView *videoOutputView;
@property (nonatomic, strong) NSURL *successCallback;
@property (nonatomic, strong) NSURL *errorCallback;
@property (nonatomic, retain) VLCMediaList *mediaList;
/* returns nil if currently playing item is not available,*/
......@@ -134,7 +131,8 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
- (void)setNeedsMetadataUpdate;
- (void)scheduleSleepTimerWithInterval:(NSTimeInterval)timeInterval;
- (void)performNavigationAction:(VLCMediaPlaybackNavigationAction)action;
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString *)subsFilePath;
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString * _Nullable)subsFilePath;
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString * _Nullable)subsFilePath completion:(void (^ __nullable)(BOOL success))completion;
- (void)openVideoSubTitlesFromFile:(NSString *)pathToFile;
NS_ASSUME_NONNULL_END
......
......@@ -70,6 +70,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
VLCDialogProvider *_dialogProvider;
NSMutableArray *_shuffleStack;
void (^_playbackCompletion)(BOOL success);
}
@end
......@@ -142,8 +143,14 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
[_mediaPlayer addPlaybackSlave:[NSURL fileURLWithPath:pathToFile] type:VLCMediaPlaybackSlaveTypeSubtitle enforce:YES];
}
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString *)subsFilePath
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString * _Nullable)subsFilePath
{
[self playMediaList: mediaList firstIndex: index subtitlesFilePath: subsFilePath completion: nil];
}
- (void)playMediaList:(VLCMediaList *)mediaList firstIndex:(NSInteger)index subtitlesFilePath:(NSString * _Nullable)subsFilePath completion:(void (^ __nullable)(BOOL success))completion
{
_playbackCompletion = completion;
self.mediaList = mediaList;
_itemInMediaListToBePlayedFirst = (int)index;
_pathToExternalSubtitlesFile = subsFilePath;
......@@ -297,20 +304,9 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
_playerIsSetup = NO;
[_shuffleStack removeAllObjects];
if (@available(iOS 10, *)) {
if (_errorCallback && _mediaPlayer.state == VLCMediaPlayerStateError && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:_errorCallback options:@{} completionHandler:nil];
else if (_successCallback && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:_successCallback options:@{} completionHandler:nil];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
/* UIApplication's replacement calls require iOS 10 or later, which we can't enforce as of yet */
if (_errorCallback && _mediaPlayer.state == VLCMediaPlayerStateError && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:_errorCallback];
else if (_successCallback && !_sessionWillRestart)
[[UIApplication sharedApplication] openURL:_successCallback];
#pragma clang diagnostic pop
if (_playbackCompletion) {
BOOL finishedPlaybackWithError = _mediaPlayer.state == VLCMediaPlayerStateError && !_sessionWillRestart;
_playbackCompletion(!finishedPlaybackWithError);
}
[[self remoteControlService] unsubscribeFromRemoteCommands];
......
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