iPhone (SDK 2.2): adusting playback volume while NOT actively playing music w/ AVFoundation?

折月煮酒 提交于 2019-12-03 10:14:13

问题


So I have an app which plays many short sound clips. I need to know when the sounds are finished playing, and I need to use mp3s, so I'm using AVFoundation for the sound playback.

When a sound is actively playing, and the user uses the hardware volume buttons, the playback volume changes. Problem is, the app is NOT constantly playing sounds, and when it's not, and the hardware buttons are used, the RINGER volume gets adjusted instead.

How do I set it up so, as long as the app is running, the user can adjust the playback volume?

Thanks!


回答1:


Turns out this can be accomplished by allocating an AVAudioPlayer with any valid sound file and calling the prepareToPlay method, without ever calling the play method.

Works perfectly.




回答2:


Start an AudioSession and don't stop it when you're not playing sounds.




回答3:


so you want to disable ringer playback volume as long as the app is running? therefore the hardware controls will only adjust the app playback sounds?

i dont think this is possible unless you are "always playing sound" for example, many games are always playing background music or what have you.




回答4:


You might be able to accomplish this by constantly playing a 0 volume sound as long as your app is running. You could then play your sound clips over it.

  • How do I play multiple sounds simultaneously?


来源:https://stackoverflow.com/questions/415442/iphone-sdk-2-2-adusting-playback-volume-while-not-actively-playing-music-w-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!