Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Let other apps play background music

Tags:

ios

swift

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.

like image 708
spencra Avatar asked Dec 24 '22 18:12

spencra


1 Answers

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

like image 168
Daniel Storm Avatar answered Jan 16 '23 03:01

Daniel Storm