Fixed background playback behind notification center.

This commit is contained in:
Tobias Hasselrot 2016-04-29 09:46:28 +02:00
parent 848e6632a3
commit 39443ae371

View File

@ -63,6 +63,11 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
name:UIApplicationWillResignActiveNotification name:UIApplicationWillResignActiveNotification
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:) selector:@selector(applicationWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification name:UIApplicationWillEnterForegroundNotification
@ -119,15 +124,20 @@ static NSString *const playbackBufferEmptyKeyPath = @"playbackBufferEmpty";
- (void)applicationWillResignActive:(NSNotification *)notification - (void)applicationWillResignActive:(NSNotification *)notification
{ {
if (_playInBackground) { if (!_paused && !_playInBackground) {
// Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html
[_playerLayer setPlayer:nil];
} else if (!_paused) {
[_player pause]; [_player pause];
[_player setRate:0.0]; [_player setRate:0.0];
} }
} }
- (void)applicationDidEnterBackground:(NSNotification *)notification
{
if (_playInBackground) {
// Needed to play sound in background. See https://developer.apple.com/library/ios/qa/qa1668/_index.html
[_playerLayer setPlayer:nil];
}
}
- (void)applicationWillEnterForeground:(NSNotification *)notification - (void)applicationWillEnterForeground:(NSNotification *)notification
{ {
[self applyModifiers]; [self applyModifiers];