iPhone AVAudioPlayer停止背景音乐 [英] iPhone AVAudioPlayer stopping background music
问题描述
所以,我刚刚注意到在我的iPod Touch,当我的应用程序触发短WAV文件中使用AVAudioPlayer播放,音乐被暂停。这正常吗?
我找不到这个任何提及,似乎像它会在某个地方注明。有没有一种方法来继续播放音乐,而我发挥我的声音?
注意:<一href=\"https://developer.apple.com/library/ios/documentation/AudioToolbox/Reference/AudioSessionServicesReference/\"相对=nofollow>的AudioSession API已经完全去$ P $ iOS中pcated 7.0
块引用>您不能在同一时间运行AVAudioPlayer和iPod播放器或MPMusicPlayer或MPMoviePlayer,没有做一点更多的工作。如果你想轻松,然后使用音频工具箱的系统声音。
如果你想要做一些额外的工作,那么你应该看看<一个href=\"http://developer.apple.com/iphone/library/DOCUMENTATION/AudioToolbox/Reference/AudioSessionServicesReference/Reference/reference.html\"相对=nofollow>音频会话:
kAudioSessionCategory_UserInterfaceSoundEffects
用于音响效果诸如触摸
反馈,爆炸,等等。
等价于
kAudioSessionCategory_AmbientSound
类,你应该使用
代替。该
kAudioSessionCategory_UserInterfaceSoundEffects
类是德precated在iPhone OS
3.0。
kAudioSessionCategory_AmbientSound
有关
长时间的雨,汽车这样的声音
发动机噪音,等等。也是
对于一起玩风格的应用程序,
这样的虚拟钢琴,一个用户播放
在iPod的音频。
当你使用这个类,从声音
内置的应用,如
iPod的,混合了您的音频。你的
音频沉默时响铃/静音
开关被设置为静音或当
屏幕锁定。
块引用>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 any reference to this, and it seems like it would be noted somewhere. Is there a way to keep the music going while I play my sounds?
解决方案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. ThekAudioSessionCategory_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.
这篇关于iPhone AVAudioPlayer停止背景音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!