iPhone AVAudioPlayer 停止背景音乐 [英] iPhone AVAudioPlayer stopping background music

查看:35
本文介绍了iPhone AVAudioPlayer 停止背景音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚刚注意到,在我的 iPod Touch 上,当我的应用触发一个简短的 wav 文件以使用 AVAudioPlayer 播放时,音乐会暂停.这是正常的吗?

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?

推荐答案

注意:AudioSession API已在 iOS 7.0 中完全弃用

如果不做更多工作,您就无法同时运行 AVAudioPlayer 和 iPod 播放器或 MPMusicPlayer 或 MPMoviePlayer.如果您想要轻松,请使用 Audio Toolbox 的系统声音.

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对于声音效果,如触摸反馈、爆炸等等.

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

相当于kAudioSessionCategory_AmbientSound您应该使用的类别反而.这kAudioSessionCategory_UserInterfaceSoundEffects类别在 iPhone 操作系统中已弃用3.0.

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

kAudioSessionCategory_AmbientSound 对于长时间的声音,如雨、汽车发动机噪音等等.也是对于一起玩"风格的应用程序,用户弹奏的这种虚拟钢琴通过 iPod 音频.

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.

当您使用此类别时,音频来自内置应用程序,例如iPod,与您的音频混合.你的响铃/静音时音频静音开关设置为静音或当屏幕锁定.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆