Let other apps play in background music

I would like to add functionality for other applications, such as Pandora or iTunes, to continue playing music while my Sprite Kit game is open.

How should I do it? I apologize for the somewhat breadth of this issue, I just can not find much information about this.

+4
source share
2 answers

Set the category AVAudioSessionto Ambient.

import AVFoundation

    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)
        try AVAudioSession.sharedInstance().setActive(true)
    }
    catch let error as NSError {
        print(error)
    }

Link to class AVAudioSession

+7
source

I would also like to add an Objective-C answer:

[[AVAudioSession sharedInstance] setCategory:@"AVAudioSessionCategoryAmbient" error:nil];
[[AVAudioSession sharedInstance]setActive:true error:nil];

I can confirm that this also worked in the Sprite Kit by using [SKAction playSoundFileNamed:] for my sound effects.

+2
source

All Articles