首页 文章

iOS应用程序中AVAudioPlayer和MPMusicPlayerController的独立音量控制 .

提问于
浏览
2

在我的应用程序中,我正在使用AVAudioPlayer播放下载的音频,同时使用MPMusicPlayerController从用户的iPod音乐库播放音频 .

我需要能够调整AVAudioPlayer实例的音量,使其比来自MPMusicPlayerController的音频更响亮 .

问题是,当我调整AVAudioPlayer的Volume属性时,它还会调整MPMusicPlayerController的音量 .

有没有任何解决方案可以让我独立控制这两个玩家的音量?

如果没有,我应该用另一种技术来做这件事吗?任何帮助表示赞赏 .

1 回答

  • 6

    看一下AVAudioSession的文档 . 例如,在AVAudioSession Programming Guide中,说明如下:

    "Finally, you can enhance a category to automatically lower the volume of other audio when your audio is playing. This could be used, for example, in an exercise application. Say the user is exercising along to their iPod when your application wants to overlay a verbal message—for instance, “You’ve been rowing for 10 minutes.” To ensure that the message from your application is intelligible, apply the kAudioSessionProperty_OtherMixableAudioShouldDuck property to your audio session. When ducking takes place, all other audio on the device—apart from phone audio—lowers in volume."

    我认为它可以解决你的问题 . 初始化AVAudioSession并设置其类别和属性的文档非常清晰且易于理解;你应该没有问题 .

相关问题