spencra spencra - 4 months ago 23
iOS Question

Let other apps play background music

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

How would I go about doing this? I apologize for the somewhat broadness of this question, I just can't find a lot of information on this.

Answer

Set your AVAudioSession category to Ambient.

import AVFoundation

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

AVAudioSession Class Reference

Comments