D
D
deleted-mezhevikin2014-10-08 10:17:16
Objective-C
deleted-mezhevikin, 2014-10-08 10:17:16

How to fix avplayer playback in background on ios 8?

On ios 8, audio playback in the background using avplayer broke, after about 10 minutes of playback in the background, it stops.
Example:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSURL *streamingURL = [NSURL URLWithString:@"http://www.radiofmgold.be/stream.php?ext=pls"];

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:streamingURL];
    [self setPlayerItem:playerItem];

    AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
    [player setAllowsExternalPlayback:NO];

    [self setPlayer:player];
    [player play];

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive: YES error: nil];

    return YES;
}

I found a post on the apple dev forum with a similar problem, but it is unanswered:
https://devforums.apple.com/message/1056436#1056436
Any thoughts on how to fix this?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
deleted-mezhevikin, 2015-03-31
@deleted-mezhevikin

It was an ios 8.0 bug that has now been fixed.

B
bartl, 2015-03-28
@bartl

Add audio to the UIBackgroundModes parameter in info.plist

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question