Commit 32afeec2 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

Introduce new VLCPlayerDisplayController class which is responsible to...

Introduce new VLCPlayerDisplayController class which is responsible to show/hide the full screen and mini player
remove playback view related stuff from VLCAppDelegate and VLCPlaylistViewController
add notifications for playback state changes, so more objects than just the VLCPlaybackControllerDelegate can react to playback state and meta data changes

(cherry picked from commit aa52c9a1)
parent 5ff67c03
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#import "VLCDownloadViewController.h" #import "VLCDownloadViewController.h"
@class VLCPlaylistViewController; @class VLCPlaylistViewController;
@class VLCPlayerDisplayController;
@interface VLCAppDelegate : UIResponder <UIApplicationDelegate> @interface VLCAppDelegate : UIResponder <UIApplicationDelegate>
- (void)updateMediaList; - (void)updateMediaList;
...@@ -33,7 +34,6 @@ ...@@ -33,7 +34,6 @@
- (void)cleanCache; - (void)cleanCache;
- (void)presentMovieViewControllerAnimated:(BOOL)animated;
- (void)openMediaFromManagedObject:(NSManagedObject *)file; - (void)openMediaFromManagedObject:(NSManagedObject *)file;
- (void)openMovieFromURL:(NSURL *)url; - (void)openMovieFromURL:(NSURL *)url;
- (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath; - (void)openMovieWithExternalSubtitleFromURL:(NSURL *)url externalSubURL:(NSString *)SubtitlePath;
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
@property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController; @property (nonatomic, readonly) VLCDropboxTableViewController *dropboxTableViewController;
@property (nonatomic, readonly) VLCDownloadViewController *downloadViewController; @property (nonatomic, readonly) VLCDownloadViewController *downloadViewController;
@property (nonatomic, readonly) VLCPlayerDisplayController *playerDisplayController;
@property (nonatomic, strong) UIWindow *window; @property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) GHRevealViewController *revealController; @property (nonatomic, strong) GHRevealViewController *revealController;
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#import "NSString+SupportedMedia.h" #import "NSString+SupportedMedia.h"
#import "UIDevice+VLC.h" #import "UIDevice+VLC.h"
#import "VLCPlaylistViewController.h" #import "VLCPlaylistViewController.h"
#import "VLCMovieViewController.h"
#import "VLCPlaybackNavigationController.h" #import "VLCPlaybackNavigationController.h"
#import "PAPasscodeViewController.h" #import "PAPasscodeViewController.h"
#import "VLCHTTPUploaderController.h" #import "VLCHTTPUploaderController.h"
...@@ -34,6 +33,7 @@ ...@@ -34,6 +33,7 @@
#import "VLCNavigationController.h" #import "VLCNavigationController.h"
#import "VLCWatchMessage.h" #import "VLCWatchMessage.h"
#import "VLCPlaybackController+MediaLibrary.h" #import "VLCPlaybackController+MediaLibrary.h"
#import "VLCPlayerDisplayController.h"
#define HAVE_FABRIC 0 #define HAVE_FABRIC 0
...@@ -51,11 +51,8 @@ ...@@ -51,11 +51,8 @@
BOOL _passcodeValidated; BOOL _passcodeValidated;
BOOL _isRunningMigration; BOOL _isRunningMigration;
BOOL _isComingFromHandoff; BOOL _isComingFromHandoff;
BOOL _presentingMovieController;
} }
@property (nonatomic, strong) VLCMovieViewController *movieViewController;
@end @end
@implementation VLCAppDelegate @implementation VLCAppDelegate
...@@ -126,7 +123,10 @@ ...@@ -126,7 +123,10 @@
_revealController.sidebarViewController = _menuViewController; _revealController.sidebarViewController = _menuViewController;
_revealController.contentViewController = navCon; _revealController.contentViewController = navCon;
self.window.rootViewController = self.revealController; _playerDisplayController = [[VLCPlayerDisplayController alloc] init];
_playerDisplayController.childViewController = self.revealController;
self.window.rootViewController = _playerDisplayController;
// necessary to avoid navbar blinking in VLCOpenNetworkStreamViewController & VLCDownloadViewController // necessary to avoid navbar blinking in VLCOpenNetworkStreamViewController & VLCDownloadViewController
_revealController.contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor]; _revealController.contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
[self.window makeKeyAndVisible]; [self.window makeKeyAndVisible];
...@@ -169,7 +169,7 @@ ...@@ -169,7 +169,7 @@
[[VLCNotificationRelay sharedRelay] addRelayLocalName:NSManagedObjectContextDidSaveNotification toRemoteName:@"org.videolan.ios-app.dbupdate"]; [[VLCNotificationRelay sharedRelay] addRelayLocalName:NSManagedObjectContextDidSaveNotification toRemoteName:@"org.videolan.ios-app.dbupdate"];
[[VLCNotificationRelay sharedRelay] addRelayLocalName:kVLCNotificationNowPlayingInfoUpdate toRemoteName:kVLCDarwinNotificationNowPlayingInfoUpdate]; [[VLCNotificationRelay sharedRelay] addRelayLocalName:VLCPlaybackControllerPlaybackMetadataDidChange toRemoteName:kVLCDarwinNotificationNowPlayingInfoUpdate];
#if HAVE_FABRIC #if HAVE_FABRIC
[Fabric with:@[CrashlyticsKit]]; [Fabric with:@[CrashlyticsKit]];
...@@ -317,10 +317,6 @@ continueUserActivity:(NSUserActivity *)userActivity ...@@ -317,10 +317,6 @@ continueUserActivity:(NSUserActivity *)userActivity
- (void)applicationWillResignActive:(UIApplication *)application - (void)applicationWillResignActive:(UIApplication *)application
{ {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
_presentingMovieController = vpc.presentingMovieViewController;
[vpc destroyCurrentViewController];
_passcodeValidated = NO; _passcodeValidated = NO;
[self validatePasscode]; [self validatePasscode];
[[MLMediaLibrary sharedMediaLibrary] applicationWillExit]; [[MLMediaLibrary sharedMediaLibrary] applicationWillExit];
...@@ -334,12 +330,6 @@ continueUserActivity:(NSUserActivity *)userActivity ...@@ -334,12 +330,6 @@ continueUserActivity:(NSUserActivity *)userActivity
} else if(_isComingFromHandoff) { } else if(_isComingFromHandoff) {
_isComingFromHandoff = NO; _isComingFromHandoff = NO;
} }
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
if (!vpc.audioOnlyPlaybackSession && _presentingMovieController)
[self presentMovieViewControllerAnimated:NO];
else
[self.playlistViewController displayMiniPlaybackViewIfNeeded];
} }
- (void)applicationWillTerminate:(UIApplication *)application - (void)applicationWillTerminate:(UIApplication *)application
...@@ -369,14 +359,6 @@ continueUserActivity:(NSUserActivity *)userActivity ...@@ -369,14 +359,6 @@ continueUserActivity:(NSUserActivity *)userActivity
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
...@@ -557,31 +539,10 @@ continueUserActivity:(NSUserActivity *)userActivity ...@@ -557,31 +539,10 @@ continueUserActivity:(NSUserActivity *)userActivity
#pragma mark - playback view handling #pragma mark - playback view handling
- (void)presentMovieViewControllerAnimated:(BOOL)animated
{
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
return;
}
UINavigationController *navCon = [[VLCPlaybackNavigationController alloc] initWithRootViewController:self.movieViewController];
[self.movieViewController prepareForMediaPlayback:[VLCPlaybackController sharedInstance]];
navCon.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:navCon animated:animated completion:nil];
}
- (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject - (void)openMediaFromManagedObject:(NSManagedObject *)mediaObject
{ {
BOOL retainFullscreenPlayback = false;
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance]; VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
if (vpc.presentingMovieViewController)
retainFullscreenPlayback = YES;
[vpc playMediaLibraryObject:mediaObject]; [vpc playMediaLibraryObject:mediaObject];
if (retainFullscreenPlayback)
[self presentMovieViewControllerAnimated:YES];
} }
- (void)openMovieFromURL:(NSURL *)url - (void)openMovieFromURL:(NSURL *)url
......
...@@ -81,8 +81,6 @@ ...@@ -81,8 +81,6 @@
#define kBlobHash @"521923d214b9ae628da7987cf621e94c4afdd726" #define kBlobHash @"521923d214b9ae628da7987cf621e94c4afdd726"
#define kVLCNotificationNowPlayingInfoUpdate @"nowPlayingInfoUpdate"
#define kVLCDarwinNotificationNowPlayingInfoUpdate @"org.videolan.ios-app.nowPlayingInfoUpdate" #define kVLCDarwinNotificationNowPlayingInfoUpdate @"org.videolan.ios-app.nowPlayingInfoUpdate"
#if TARGET_IPHONE_SIMULATOR #if TARGET_IPHONE_SIMULATOR
......
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
#import "VLCFrostedGlasView.h" #import "VLCFrostedGlasView.h"
@class VLCPlaybackController;
@interface VLCMiniPlaybackView : VLCFrostedGlasView @interface VLCMiniPlaybackView : VLCFrostedGlasView
// just a state keeper for animation, has no other implementation // just a state keeper for animation, has no other implementation
@property (nonatomic) BOOL visible; @property (nonatomic) BOOL visible;
- (void)setupForWork;
- (void)setupForWork:(VLCPlaybackController *)playbackController;
@end @end
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
UIButton *_expandButton; UIButton *_expandButton;
UILabel *_metaDataLabel; UILabel *_metaDataLabel;
} }
@property (nonatomic, weak) VLCPlaybackController *playbackController;
@end @end
...@@ -90,30 +91,27 @@ ...@@ -90,30 +91,27 @@
- (void)previousAction:(id)sender - (void)previousAction:(id)sender
{ {
[[VLCPlaybackController sharedInstance] backward]; [self.playbackController backward];
} }
- (void)playPauseAction:(id)sender - (void)playPauseAction:(id)sender
{ {
[[VLCPlaybackController sharedInstance] playPause]; [self.playbackController playPause];
} }
- (void)nextAction:(id)sender - (void)nextAction:(id)sender
{ {
[[VLCPlaybackController sharedInstance] forward]; [self.playbackController forward];
} }
- (void)pushFullPlaybackView:(id)sender - (void)pushFullPlaybackView:(id)sender
{ {
[VLCPlaybackController sharedInstance].videoOutputView = nil; [[UIApplication sharedApplication] sendAction:@selector(showFullscreenPlayback) to:nil from:self forEvent:nil];
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate presentMovieViewControllerAnimated:YES];
} }
- (void)setupForWork - (void)setupForWork:(VLCPlaybackController *)playbackController
{ {
VLCPlaybackController *playbackController = [VLCPlaybackController sharedInstance]; self.playbackController = playbackController;
if (playbackController.isPlaying) if (playbackController.isPlaying)
[_playPauseButton setImage:[UIImage imageNamed:@"pauseIcon"] forState:UIControlStateNormal]; [_playPauseButton setImage:[UIImage imageNamed:@"pauseIcon"] forState:UIControlStateNormal];
else else
...@@ -155,9 +153,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -155,9 +153,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
_videoView = [[UIView alloc] initWithFrame:_artworkView.frame]; _videoView = [[UIView alloc] initWithFrame:_artworkView.frame];
[_videoView setClipsToBounds:YES]; [_videoView setClipsToBounds:YES];
[self addSubview:_videoView]; [self addSubview:_videoView];
controller.videoOutputView = _videoView;
if (!controller.presentingMovieViewController)
controller.videoOutputView = _videoView;
} }
NSString *metaDataString; NSString *metaDataString;
...@@ -173,15 +169,4 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -173,15 +169,4 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
_metaDataLabel.text = metaDataString; _metaDataLabel.text = metaDataString;
} }
- (void)presentingViewControllerShouldBeClosed:(VLCPlaybackController *)controller
{
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.playlistViewController displayMiniPlaybackViewIfNeeded];
}
- (void)presentingViewControllerShouldBeClosedAfterADelay:(VLCPlaybackController *)controller
{
[self presentingViewControllerShouldBeClosed:controller];
}
@end @end
...@@ -116,4 +116,7 @@ ...@@ -116,4 +116,7 @@
- (BOOL)rotationIsDisabled; - (BOOL)rotationIsDisabled;
- (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated;
- (void)showStatusMessage:(NSString *)statusMessage;
@end @end
...@@ -416,6 +416,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -416,6 +416,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[self.view addSubview:_sleepTimerContainer]; [self.view addSubview:_sleepTimerContainer];
} }
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidStop:) name:VLCPlaybackControllerPlaybackDidStop object:nil];
} }
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
...@@ -440,7 +442,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -440,7 +442,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
VLCPlaybackController *vpc = self.playbackController; VLCPlaybackController *vpc = self.playbackController;
vpc.delegate = self; vpc.delegate = self;
vpc.presentingMovieViewController = YES;
[vpc recoverPlaybackState]; [vpc recoverPlaybackState];
[self setControlsHidden:NO animated:YES]; [self setControlsHidden:NO animated:YES];
...@@ -500,8 +501,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -500,8 +501,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
- (void)viewWillDisappear:(BOOL)animated - (void)viewWillDisappear:(BOOL)animated
{ {
VLCPlaybackController *vpc = self.playbackController; VLCPlaybackController *vpc = self.playbackController;
vpc.videoOutputView = nil; if (vpc.videoOutputView == self.movieView) {
vpc.presentingMovieViewController = NO; vpc.videoOutputView = nil;
}
_viewAppeared = NO; _viewAppeared = NO;
if (_idleTimer) { if (_idleTimer) {
...@@ -685,10 +687,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -685,10 +687,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
- (IBAction)closePlayback:(id)sender - (IBAction)closePlayback:(id)sender
{ {
LOCKCHECK; LOCKCHECK;
[[UIApplication sharedApplication] sendAction:@selector(closeFullscreenPlayback) to:nil from:self forEvent:nil];
[self presentingViewControllerShouldBeClosed:nil];
} }
- (IBAction)positionSliderAction:(UISlider *)sender - (IBAction)positionSliderAction:(UISlider *)sender
{ {
LOCKCHECK; LOCKCHECK;
...@@ -811,15 +812,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) { ...@@ -811,15 +812,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[self _resetIdleTimer]; [self _resetIdleTimer];
} }
- (void)presentingViewControllerShouldBeClosed:(VLCPlaybackController *)controller - (void)playbackDidStop:(NSNotification *)notification
{
[self setControlsHidden:NO animated:NO];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
- (void)presentingViewControllerShouldBeClosedAfterADelay:(VLCPlaybackController *)controller
{ {
[self performSelector:@selector(presentingViewControllerShouldBeClosed:) withObject:nil afterDelay:2.]; [self closePlayback:nil];
} }
- (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState - (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState
...@@ -854,7 +849,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -854,7 +849,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
- (void)showStatusMessage:(NSString *)statusMessage forPlaybackController:(VLCPlaybackController *)controller - (void)showStatusMessage:(NSString *)statusMessage forPlaybackController:(VLCPlaybackController *)controller
{ {
[self.statusLabel showStatusMessage:statusMessage]; [self showStatusMessage:statusMessage];
} }
- (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller - (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller
...@@ -1014,15 +1009,19 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -1014,15 +1009,19 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
[self _resetIdleTimer]; [self _resetIdleTimer];
} }
- (void)showStatusMessage:(NSString *)statusMessage
{
[self.statusLabel showStatusMessage:statusMessage];
}
#pragma mark - multi-select delegation #pragma mark - multi-select delegation
- (void)toggleUILock - (void)toggleUILock
{ {
_interfaceIsLocked = !_interfaceIsLocked; _interfaceIsLocked = !_interfaceIsLocked;
if (_interfaceIsLocked)
_multiSelectionView.displayLock = YES; _multiSelectionView.displayLock = _interfaceIsLocked;
else self.backButton.enabled = !_interfaceIsLocked;
_multiSelectionView.displayLock = NO;
} }
- (void)toggleEqualizer - (void)toggleEqualizer
......
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
#import "VLCEqualizerView.h" #import "VLCEqualizerView.h"
extern NSString *const VLCPlaybackControllerPlaybackDidStart;
extern NSString *const VLCPlaybackControllerPlaybackDidPause;
extern NSString *const VLCPlaybackControllerPlaybackDidResume;
extern NSString *const VLCPlaybackControllerPlaybackDidStop;
extern NSString *const VLCPlaybackControllerPlaybackDidFail;
extern NSString *const VLCPlaybackControllerPlaybackMetadataDidChange;
@class VLCPlaybackController; @class VLCPlaybackController;
@protocol VLCPlaybackControllerDelegate <NSObject> @protocol VLCPlaybackControllerDelegate <NSObject>
...@@ -24,8 +31,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -24,8 +31,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
currentMediaHasChapters:(BOOL)currentMediaHasChapters currentMediaHasChapters:(BOOL)currentMediaHasChapters
forPlaybackController:(VLCPlaybackController *)controller; forPlaybackController:(VLCPlaybackController *)controller;
- (void)prepareForMediaPlayback:(VLCPlaybackController *)controller; - (void)prepareForMediaPlayback:(VLCPlaybackController *)controller;
- (void)presentingViewControllerShouldBeClosed:(VLCPlaybackController *)controller;
- (void)presentingViewControllerShouldBeClosedAfterADelay:(VLCPlaybackController *)controller;
- (void)showStatusMessage:(NSString *)statusMessage forPlaybackController:(VLCPlaybackController *)controller; - (void)showStatusMessage:(NSString *)statusMessage forPlaybackController:(VLCPlaybackController *)controller;
- (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller - (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller
title:(NSString *)title title:(NSString *)title
...@@ -68,7 +73,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -68,7 +73,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
@property (nonatomic, readonly) BOOL currentMediaHasTrackToChooseFrom; @property (nonatomic, readonly) BOOL currentMediaHasTrackToChooseFrom;
@property (nonatomic, readonly) BOOL activePlaybackSession; @property (nonatomic, readonly) BOOL activePlaybackSession;
@property (nonatomic, readonly) BOOL audioOnlyPlaybackSession; @property (nonatomic, readonly) BOOL audioOnlyPlaybackSession;
@property (nonatomic, readwrite) BOOL presentingMovieViewController;
+ (VLCPlaybackController *)sharedInstance; + (VLCPlaybackController *)sharedInstance;
...@@ -85,6 +89,5 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom ...@@ -85,6 +89,5 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
- (void)setNeedsMetadataUpdate; - (void)setNeedsMetadataUpdate;
- (void)destroyCurrentViewController;
@end @end
...@@ -23,9 +23,15 @@ ...@@ -23,9 +23,15 @@
#import <MediaPlayer/MediaPlayer.h> #import <MediaPlayer/MediaPlayer.h>
#import "VLCThumbnailsCache.h" #import "VLCThumbnailsCache.h"
#import <WatchKit/WatchKit.h> #import <WatchKit/WatchKit.h>
#import "VLCAppDelegate.h"
#import "VLCPlaylistViewController.h" #import "VLCPlaylistViewController.h"
NSString *const VLCPlaybackControllerPlaybackDidStart = @"VLCPlaybackControllerPlaybackDidStart";
NSString *const VLCPlaybackControllerPlaybackDidPause = @"VLCPlaybackControllerPlaybackDidPause";
NSString *const VLCPlaybackControllerPlaybackDidResume = @"VLCPlaybackControllerPlaybackDidResume";
NSString *const VLCPlaybackControllerPlaybackDidStop = @"VLCPlaybackControllerPlaybackDidStop";
NSString *const VLCPlaybackControllerPlaybackMetadataDidChange = @"VLCPlaybackControllerPlaybackMetadataDidChange";
NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPlaybackDidFail";
@interface VLCPlaybackController () <AVAudioSessionDelegate, VLCMediaPlayerDelegate, VLCMediaDelegate> @interface VLCPlaybackController () <AVAudioSessionDelegate, VLCMediaPlayerDelegate, VLCMediaDelegate>
{ {
BOOL _playerIsSetup; BOOL _playerIsSetup;
...@@ -303,10 +309,10 @@ ...@@ -303,10 +309,10 @@
[self subscribeRemoteCommands]; [self subscribeRemoteCommands];
[[(VLCAppDelegate *)[UIApplication sharedApplication].delegate playlistViewController] displayMiniPlaybackViewIfNeeded];
_playerIsSetup = YES; _playerIsSetup = YES;
_mediaWasJustStarted = YES; _mediaWasJustStarted = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStart object:self];
} }
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
...@@ -357,10 +363,14 @@ ...@@ -357,10 +363,14 @@
else if (self.successCallback) else if (self.successCallback)
[[UIApplication sharedApplication] openURL:self.successCallback]; [[UIApplication sharedApplication] openURL:self.successCallback];
[self destroyCurrentViewController];
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil; [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nil;
[self unsubscribeFromRemoteCommand]; [self unsubscribeFromRemoteCommand];
if (_playbackFailed) {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidFail object:self];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidStop object:self];
}
} }
- (void)_savePlaybackState - (void)_savePlaybackState
...@@ -517,6 +527,7 @@ ...@@ -517,6 +527,7 @@
- (void)mediaPlayerStateChanged:(NSNotification *)aNotification - (void)mediaPlayerStateChanged:(NSNotification *)aNotification
{ {
VLCMediaPlayerState currentState = _mediaPlayer.state; VLCMediaPlayerState currentState = _mediaPlayer.state;
if (currentState == VLCMediaPlayerStateBuffering) { if (currentState == VLCMediaPlayerStateBuffering) {
/* attach delegate */ /* attach delegate */
_mediaPlayer.media.delegate = self; _mediaPlayer.media.delegate = self;
...@@ -527,21 +538,18 @@ ...@@ -527,21 +538,18 @@
[_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingSubtitlesFontColor]]; [_mediaPlayer performSelector:@selector(setTextRendererFontColor:) withObject:[[NSUserDefaults standardUserDefaults] objectForKey:kVLCSettingSubtitlesFontColor]];
} else if (currentState == VLCMediaPlayerStateError) { } else if (currentState == VLCMediaPlayerStateError) {
_playbackFailed = YES; _playbackFailed = YES;
if ([self.delegate respondsToSelector:@selector(presentingViewControllerShouldBeClosedAfterADelay:)])
[self.delegate presentingViewControllerShouldBeClosedAfterADelay:self];
[self stopPlayback]; [self stopPlayback];
} else if ((currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) && _listPlayer.repeatMode == VLCDoNotRepeat) { } else if ((currentState == VLCMediaPlayerStateEnded || currentState == VLCMediaPlayerStateStopped) && _listPlayer.repeatMode == VLCDoNotRepeat) {
if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == _listPlayer.mediaList.count - 1) { if ([_listPlayer.mediaList indexOfMedia:_mediaPlayer.media] == _listPlayer.mediaList.count - 1) {
[self destroyCurrentViewController];
[self stopPlayback]; [self stopPlayback];
return; return;
} }
} else { }
/* disable video decoding if we have no place to show */
if (_mediaPlayer.numberOfAudioTracks > 0) { /* disable video decoding if we have no place to show */
if (_videoOutputViewWrapper == nil) if (_mediaPlayer.numberOfAudioTracks > 0) {
_mediaPlayer.currentVideoTrackIndex = -1; if (_videoOutputViewWrapper == nil)
} _mediaPlayer.currentVideoTrackIndex = -1;
} }
if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)]) if ([self.delegate respondsToSelector:@selector(mediaPlayerStateChanged:isPlaying:currentMediaHasTrackToChooseFrom:currentMediaHasChapters:forPlaybackController:)])
...@@ -560,14 +568,18 @@ ...@@ -560,14 +568,18 @@
if ([_mediaPlayer isPlaying]) { if ([_mediaPlayer isPlaying]) {
[_listPlayer pause]; [_listPlayer pause];
[self _savePlaybackState]; [self _savePlaybackState];
} else [[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidPause object:self];
} else {
[_listPlayer play]; [_listPlayer play];
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackDidResume object:self];
}
} }
- (void)forward - (void)forward
{ {
if (_mediaList) { if (_mediaList) {
[_listPlayer next]; [_listPlayer next];
[[NSNotificationCenter defaultCenter] postNotificationName:VLCPlaybackControllerPlaybackMetadataDidChange object:self];
} else { } else {
NSNumber *skipLength = [[NSUserDefaults standardUserDefaults] valueForKey:kVLCSettingPlaybackForwardSkipLength]; NSNumber *skipLength = [[NSUserDefaults standardUserDefaults] valueForKey:kVLCSettingPlaybackForwardSkipLength];
[_mediaPlayer jumpForward:skipLength.intValue]; [_mediaPlayer jumpForward:skipLength.intValue];
...@@ -578,6 +590,7 @@ ...@@ -578,6 +590,7 @@
{ {
if (_mediaList) {