iPhone AVAudioPlayer stopping background music

后端 未结 3 403
旧巷少年郎
旧巷少年郎 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:51

    Note: The AudioSession API has been completely deprecated in iOS 7.0

    You can't run AVAudioPlayer and the iPod player or MPMusicPlayer or MPMoviePlayer at the same time, without doing a bit more work. If you want easy, then use Audio Toolbox's System Sounds.

    If you want to do some extra work, then you should look at Audio Sessions:

    kAudioSessionCategory_UserInterfaceSoundEffects For sound effects such as touch feedback, explosions, and so on.

    Equivalent to the kAudioSessionCategory_AmbientSound category, which you should use instead. The kAudioSessionCategory_UserInterfaceSoundEffects category is deprecated in iPhone OS 3.0.

    kAudioSessionCategory_AmbientSound For long-duration sounds such as rain, car engine noise, and so on. It is also for “play along” style applications, such a virtual piano that a user plays over iPod audio.

    When you use this category, audio from built-in applications, such as the iPod, mixes with your audio. Your audio is silenced when the Ring/Silent switch is set to silent or when the screen locks.

提交回复
热议问题