iPhone AVAudioPlayer stopping background music

后端 未结 3 400
旧巷少年郎
旧巷少年郎 2020-12-08 11:07

So I\'ve just noticed that on my iPod Touch, when my app triggers a short wav file to play using AVAudioPlayer, the music gets paused. Is this normal?

I can\'t find

3条回答
  •  情歌与酒
    2020-12-08 11:37

    Depending on your requirements, playing system sounds might not be enough, take a look at the session options, e.g. MixWithOthers

    struct AVAudioSessionCategoryOptions : OptionSetType {
        init(rawValue rawValue: UInt)
        static var MixWithOthers: AVAudioSessionCategoryOptions { get }
        static var DuckOthers: AVAudioSessionCategoryOptions { get }
        static var AllowBluetooth: AVAudioSessionCategoryOptions { get }
        static var DefaultToSpeaker: AVAudioSessionCategoryOptions { get }
        static var InterruptSpokenAudioAndMixWithOthers: AVAudioSessionCategoryOptions { get }
    }
    

    When you start your session, pass the MixWithOthers option, maybe the DuckOthers (will drop the ipod volume when your sound plays) is another option.

提交回复
热议问题