Commit 78816188 authored by Soomin Lee's avatar Soomin Lee Committed by Carola
Browse files

VLCPlaybackController: Migrate deprecated AVAudioSessionDelegate


Signed-off-by: Carola's avatarCarola Nitz <nitz.carola@googlemail.com>
parent 7e7fe028
...@@ -40,11 +40,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) { ...@@ -40,11 +40,7 @@ typedef NS_ENUM(NSUInteger, VLCAspectRatio) {
VLCAspectRatioSixteenToTen, VLCAspectRatioSixteenToTen,
}; };
@interface VLCPlaybackController () <VLCMediaPlayerDelegate, @interface VLCPlaybackController () <VLCMediaPlayerDelegate, VLCMediaDelegate, VLCRemoteControlServiceDelegate>
#if TARGET_OS_IOS
AVAudioSessionDelegate,
#endif
VLCMediaDelegate, VLCRemoteControlServiceDelegate>
{ {
VLCRemoteControlService *_remoteControlService; VLCRemoteControlService *_remoteControlService;
VLCMediaPlayer *_mediaPlayer; VLCMediaPlayer *_mediaPlayer;
...@@ -52,7 +48,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate> ...@@ -52,7 +48,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
BOOL _playerIsSetup; BOOL _playerIsSetup;
BOOL _shouldResumePlaying; BOOL _shouldResumePlaying;
BOOL _sessionWillRestart; BOOL _sessionWillRestart;
BOOL _shouldResumePlayingAfterInteruption;
NSString *_pathToExternalSubtitlesFile; NSString *_pathToExternalSubtitlesFile;
int _itemInMediaListToBePlayedFirst; int _itemInMediaListToBePlayedFirst;
...@@ -110,6 +105,9 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate> ...@@ -110,6 +105,9 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
[defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:) [defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
name:AVAudioSessionRouteChangeNotification object:nil]; name:AVAudioSessionRouteChangeNotification object:nil];
[defaultCenter addObserver:self selector:@selector(handleInterruption:)
name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
// appkit because we neeed to know when we go to background in order to stop the video, so that we don't crash // 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:) [defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil]; name:UIApplicationWillResignActiveNotification object:nil];
...@@ -171,10 +169,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate> ...@@ -171,10 +169,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
return; return;
} }
#if TARGET_OS_IOS
[[AVAudioSession sharedInstance] setDelegate:self];
#endif
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (!self.mediaList) { if (!self.mediaList) {
...@@ -1008,20 +1002,23 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate> ...@@ -1008,20 +1002,23 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
return [_mediaPlayer preAmplification]; return [_mediaPlayer preAmplification];
} }
#pragma mark - AVSession delegate #pragma mark - AVAudioSession Notification Observers
- (void)beginInterruption
- (void)handleInterruption:(NSNotification *)notification
{ {
if ([_mediaPlayer isPlaying]) { NSDictionary *userInfo = notification.userInfo;
[_mediaPlayer pause];
_shouldResumePlayingAfterInteruption = YES; if (!userInfo || !userInfo[AVAudioSessionInterruptionTypeKey]) {
return;
} }
}
- (void)endInterruption NSUInteger interruptionType = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
{
if (_shouldResumePlayingAfterInteruption) { if (interruptionType == AVAudioSessionInterruptionTypeBegan) {
[_mediaPlayer pause];
} else if (interruptionType == AVAudioSessionInterruptionTypeEnded
&& [userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue] == AVAudioSessionInterruptionOptionShouldResume) {
[_mediaPlayer play]; [_mediaPlayer play];
_shouldResumePlayingAfterInteruption = NO;
} }
} }
......
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