在iOS应用程序中的AVAudioPlayer和MPMusicPlayerController的独立音量控制。 [英] Independent Volume control of AVAudioPlayer and MPMusicPlayerController in iOS App.

查看:1438
本文介绍了在iOS应用程序中的AVAudioPlayer和MPMusicPlayerController的独立音量控制。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Within my application, I am playing downloaded audio using an AVAudioPlayer, while simultaneously playing audio from the user's iPod music library with an MPMusicPlayerController.

我需要能够调整AVAudioPlayer实例的音量,使音量比来自MPMusicPlayerController的音量大

I need to be able to adjust the Volume of the AVAudioPlayer instance so that it's louder than the audio coming from the MPMusicPlayerController.

问题是,当我调整AVAudioPlayer的Volume属性时,它也
调整MPMusicPlayerController的音量。

The problem is, when I adjust the Volume property of the AVAudioPlayer, it also adjusts the volume of the MPMusicPlayerController.

有没有任何解决方案,这将允许我独立控制
这两个玩家的音量?

Is there any solution which would allow me to independently control the volume of these two players?

如果没有,是否有其他技术我应该使用?任何帮助是赞赏。

If not, is there another technique I should use to do this? Any help is appreciated.

推荐答案

查看AVAudioSession的文档。例如,在 AVAudioSession编程指南,说明如下:

Take a look at the documentation for AVAudioSession. For example, in the AVAudioSession Programming Guide, says the following:

最后,您可以增强类别,以便在播放音频时自动降低其他音频的音量,例如,在锻炼应用程序中使用。当你的应用程序想覆盖一个语言消息,例如,你已经划船10分钟。为了确保来自你的应用程序的消息是可理解的,应用kAudioSessionProperty_OtherMixableAudioShouldDuck属性到您的音频会话。

"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并设置其类别和属性的文档非常清晰易懂;你应该没有麻烦。

I think it might solve your problem. The documentation on initializing an AVAudioSession and setting its categories and properties is pretty clear and easy to follow; you should have no trouble.

这篇关于在iOS应用程序中的AVAudioPlayer和MPMusicPlayerController的独立音量控制。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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