1

iOS 9.0

I can't seem to get this running, looked at the docs, headers, it all seems fine but obviouly something is missing.

1) info.plist has the UIBackgorundModes being an array with one item "audio".

2) Using AVfoundations AVAudioPlayer.

3) Set the session category to be AVAudioSessionCatergoryPlayback

4) Set the session mode explicitly to be AVAudioSessionModeDefault (see answer from Bamsworld)

5) Implemented remote control and play now info.

6) Using notifications

But audio keeps getting paused when in background. What am I missing?


Here's the session

- (void)setupAudioSession{

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];

    //Sugested by Bamsworld
    NSError *setModeError = nil;
    [audioSession setMode:AVAudioSessionModeDefault error:&setModeError];
    if (setModeError) NSLog(@"mlAlbum: Error setting mode! %ld", (long)setModeError.code);

    NSError *setCategoryError = nil;
    [audioSession setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
    if (setCategoryError) NSLog(@"mlAlbum: Error setting category! %ld", (long)setCategoryError.code);

    NSError *activationError = nil;
    [audioSession setActive:YES error:&activationError];
    if (activationError) NSLog(@"mlAlbum: Audio session activation error.\n %ld", (long)activationError.code) ;

}

Gets called every play.

matiaslanzi
  • 103
  • 8
  • This list of steps taken looks ok, however a more detailed look at these steps taken would be useful. I would start with the configuration of the AVAudioSession singleton. It may be useful if you could post the code that configs and manages the audio session. Also confirm that your AVAudioPlayer instance is not being released when entering background and UIBackgroundModes key in info plist is of type array with 'audio' as a string (this I assume by your post has been done correctly) – Bamsworld Nov 20 '15 at 01:49
  • Thank you for the edit. AVAudioSessionDelegate protocol is deprecated from iOS 6 - you should be using notifications, also I would suggest explicitly set the session mode before setting the category. Reason is the mode is global and can be altered by other apps. [audioSession setMode: AVAudioSessionModeDefault error:nil] – Bamsworld Nov 20 '15 at 02:23
  • Added the code to set up the session mode. Checked for released player after setting up notifications. The player exists when in background but it's paused. It resumes playing when brought back to foreground. – matiaslanzi Nov 20 '15 at 02:36
  • I thought that was the plist entry for. Thanks for your help and sugestions. – matiaslanzi Nov 20 '15 at 03:13

1 Answers1

1

Answered in another post: How to handle background audio playing while iOS device is locked or on another application?

Under the capabilities tab of the Xcode project, need to turn on Background Modes.

Capabilities tab

Community
  • 1
  • 1
matiaslanzi
  • 103
  • 8