3254523
3254523

Reputation: 3026

How to allow audio to continue to play when app is backgrounded?

I'm having issues getting audio to play when the app is backgrounded. I have turned on Background Modes in Targets>Capabilities, along with checking boxes for the Audio, Airplay and Picture in Picture & Background fetch modes.

I'm using Core Audio(not sure if that makes a difference). Am i missing a step to get audio to play in the background? Audio plays completely fine when the client is in the foreground, but once the app is backgrounded, audio stops

Upvotes: 0

Views: 178

Answers (1)

Michael M. Myers
Michael M. Myers

Reputation: 2515

Make sure you also have an active audio session, code sample is from this Apple Tech Q&A:

#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *setCategoryError = nil;
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (!success) { /* handle the error condition */ }

NSError *activationError = nil;
success = [audioSession setActive:YES error:&activationError];
if (!success) { /* handle the error condition */ }

Upvotes: 1

Related Questions