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) {
VLCAspectRatioSixteenToTen,
};
@interface VLCPlaybackController () <VLCMediaPlayerDelegate,
#if TARGET_OS_IOS
AVAudioSessionDelegate,
#endif
VLCMediaDelegate, VLCRemoteControlServiceDelegate>
@interface VLCPlaybackController () <VLCMediaPlayerDelegate, VLCMediaDelegate, VLCRemoteControlServiceDelegate>
{
VLCRemoteControlService *_remoteControlService;
VLCMediaPlayer *_mediaPlayer;
......@@ -52,7 +48,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
BOOL _playerIsSetup;
BOOL _shouldResumePlaying;
BOOL _sessionWillRestart;
BOOL _shouldResumePlayingAfterInteruption;
NSString *_pathToExternalSubtitlesFile;
int _itemInMediaListToBePlayedFirst;
......@@ -110,6 +105,9 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
[defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
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
[defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
......@@ -171,10 +169,6 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
return;
}
#if TARGET_OS_IOS
[[AVAudioSession sharedInstance] setDelegate:self];
#endif
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (!self.mediaList) {
......@@ -1008,20 +1002,23 @@ VLCMediaDelegate, VLCRemoteControlServiceDelegate>
return [_mediaPlayer preAmplification];
}
#pragma mark - AVSession delegate
- (void)beginInterruption
#pragma mark - AVAudioSession Notification Observers
- (void)handleInterruption:(NSNotification *)notification
{
if ([_mediaPlayer isPlaying]) {
[_mediaPlayer pause];
_shouldResumePlayingAfterInteruption = YES;
NSDictionary *userInfo = notification.userInfo;
if (!userInfo || !userInfo[AVAudioSessionInterruptionTypeKey]) {
return;
}
}
- (void)endInterruption
{
if (_shouldResumePlayingAfterInteruption) {
NSUInteger interruptionType = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
if (interruptionType == AVAudioSessionInterruptionTypeBegan) {
[_mediaPlayer pause];
} else if (interruptionType == AVAudioSessionInterruptionTypeEnded
&& [userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue] == AVAudioSessionInterruptionOptionShouldResume) {
[_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