Commit 1b2bf10b authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

use VLCPlaybackController for playback control only present...

use VLCPlaybackController for playback control only present VLCMoviewViewController when the app is active DRY app delegate by moving VLCMovieViewController initialization and presentation to methods
parent a6fa0a68
...@@ -46,12 +46,13 @@ ...@@ -46,12 +46,13 @@
VLCDropboxTableViewController *_dropboxTableViewController; VLCDropboxTableViewController *_dropboxTableViewController;
int _idleCounter; int _idleCounter;
int _networkActivityCounter; int _networkActivityCounter;
VLCMovieViewController *_movieViewController;
BOOL _passcodeValidated; BOOL _passcodeValidated;
BOOL _isRunningMigration; BOOL _isRunningMigration;
BOOL _isComingFromHandoff; BOOL _isComingFromHandoff;
} }
@property (nonatomic, strong) VLCMovieViewController *movieViewController;
@end @end
@implementation VLCAppDelegate @implementation VLCAppDelegate
...@@ -361,6 +362,10 @@ ...@@ -361,6 +362,10 @@
} else if(_isComingFromHandoff) { } else if(_isComingFromHandoff) {
_isComingFromHandoff = NO; _isComingFromHandoff = NO;
} }
if ([VLCPlaybackController sharedInstance].isPlaying && !self.movieViewController.presentingViewController) {
[self presentMovieViewController];
}
} }
- (void)applicationWillTerminate:(UIApplication *)application - (void)applicationWillTerminate:(UIApplication *)application
...@@ -390,6 +395,15 @@ ...@@ -390,6 +395,15 @@
return _downloadViewController; return _downloadViewController;
} }
- (VLCMovieViewController *)movieViewController
{
if (!_movieViewController) {
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
[VLCPlaybackController sharedInstance].delegate = _movieViewController;
}
return _movieViewController;
}
#pragma mark - media discovering #pragma mark - media discovering
- (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading - (void)mediaFileAdded:(NSString *)fileName loading:(BOOL)isLoading
...@@ -569,11 +583,19 @@ ...@@ -569,11 +583,19 @@
#pragma mark - playback view handling #pragma mark - playback view handling
- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject - (void)presentMovieViewController
{ {
if (!_movieViewController) if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil]; return;
}
UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:self.movieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
}
- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance]; VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
if ([mediaObject isKindOfClass:[MLFile class]]) if ([mediaObject isKindOfClass:[MLFile class]])
...@@ -583,11 +605,8 @@ ...@@ -583,11 +605,8 @@
else if ([mediaObject isKindOfClass:[MLShowEpisode class]]) else if ([mediaObject isKindOfClass:[MLShowEpisode class]])
vpc.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject; vpc.fileFromMediaLibrary = [(MLShowEpisode*)mediaObject files].anyObject;
[(MLFile *)vpc.fileFromMediaLibrary setUnread:@(NO)]; [(MLFile *)vpc.fileFromMediaLibrary setUnread:@(NO)];
vpc.delegate = _movieViewController;
UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController]; [self presentMovieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
[vpc startPlayback]; [vpc startPlayback];
} }
...@@ -596,19 +615,14 @@ ...@@ -596,19 +615,14 @@
successCallback:(NSURL *)successCallback successCallback:(NSURL *)successCallback
errorCallback:(NSURL *)errorCallback errorCallback:(NSURL *)errorCallback
{ {
if (!_movieViewController)
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance]; VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.url = url; vpc.url = url;
vpc.successCallback = successCallback; vpc.successCallback = successCallback;
vpc.errorCallback = errorCallback; vpc.errorCallback = errorCallback;
vpc.delegate = _movieViewController;
UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController]; [self presentMovieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
[vpc startPlayback]; [vpc startPlayback];
} }
...@@ -620,37 +634,25 @@ ...@@ -620,37 +634,25 @@
- (void)openMediaList:(VLCMediaList *)list atIndex:(int)index - (void)openMediaList:(VLCMediaList *)list atIndex:(int)index
{ {
if (!_movieViewController)
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance]; VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.mediaList = list; vpc.mediaList = list;
vpc.itemInMediaListToBePlayedFirst = index; vpc.itemInMediaListToBePlayedFirst = index;
vpc.pathToExternalSubtitlesFile = nil; vpc.pathToExternalSubtitlesFile = nil;
vpc.delegate = _movieViewController;
UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController]; [self presentMovieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
[vpc startPlayback]; [vpc startPlayback];
} }
- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath - (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath
{ {
if (!_movieViewController)
_movieViewController = [[VLCMovieViewController alloc] initWithNibName:nil bundle:nil];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance]; VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
vpc.url = url; vpc.url = url;
vpc.pathToExternalSubtitlesFile = SubtitlePath; vpc.pathToExternalSubtitlesFile = SubtitlePath;
vpc.delegate = _movieViewController;
UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:_movieViewController]; [self presentMovieViewController];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:YES completion:nil];
[vpc startPlayback]; [vpc startPlayback];
} }
...@@ -669,12 +671,12 @@ ...@@ -669,12 +671,12 @@
if ([userInfo[@"name"] isEqualToString:@"getNowPlayingInfo"]) { if ([userInfo[@"name"] isEqualToString:@"getNowPlayingInfo"]) {
responseDict = [self nowPlayingResponseDict]; responseDict = [self nowPlayingResponseDict];
} else if ([userInfo[@"name"] isEqualToString:@"playpause"]) { } else if ([userInfo[@"name"] isEqualToString:@"playpause"]) {
[_movieViewController playPause]; [[VLCPlaybackController sharedInstance] playPause];
responseDict = @{@"playing": @(_movieViewController.isPlaying)}; responseDict = @{@"playing": @([VLCPlaybackController sharedInstance].isPlaying)};
} else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) { } else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) {
[_movieViewController forward:nil]; [[VLCPlaybackController sharedInstance] forward];
} else if ([userInfo[@"name"] isEqualToString:@"skipBackward"]) { } else if ([userInfo[@"name"] isEqualToString:@"skipBackward"]) {
[_movieViewController backward:nil]; [[VLCPlaybackController sharedInstance] backward];
} else if ([userInfo[@"name"] isEqualToString:@"playFile"]) { } else if ([userInfo[@"name"] isEqualToString:@"playFile"]) {
[self playFileFromWatch:userInfo[@"userInfo"]]; [self playFileFromWatch:userInfo[@"userInfo"]];
} else { } else {
......
...@@ -84,8 +84,6 @@ ...@@ -84,8 +84,6 @@
@property (nonatomic, strong) IBOutlet UILabel *trackNameLabel; @property (nonatomic, strong) IBOutlet UILabel *trackNameLabel;
@property (nonatomic, strong) IBOutlet UIImageView *artworkImageView; @property (nonatomic, strong) IBOutlet UIImageView *artworkImageView;
@property (nonatomic, readonly, getter=isPlaying) BOOL playing;
- (IBAction)closePlayback:(id)sender; - (IBAction)closePlayback:(id)sender;
- (IBAction)positionSliderAction:(id)sender; - (IBAction)positionSliderAction:(id)sender;
......
...@@ -847,12 +847,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -847,12 +847,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
self.videoFilterButton.hidden = audioOnly; self.videoFilterButton.hidden = audioOnly;
} }
- (BOOL)isPlaying
{
return [VLCPlaybackController sharedInstance].isPlaying;
}
- (IBAction)playPause - (IBAction)playPause
{ {
LOCKCHECK; LOCKCHECK;
......
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