iOS App 中 AVAudioPlayer 和 MPMusicPlayerController 的独立音量控制。

发布于 2024-11-27 09:14:32 字数 319 浏览 3 评论 0原文

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

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

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

有什么解决方案可以让我独立控制音量 这两个球员?

如果没有,我应该使用另一种技术来做到这一点吗?任何帮助表示赞赏。

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.

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み青杉依旧 2024-12-04 09:14:32

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

“最后,您可以增强一个类别,以在播放您的音频时自动降低其他音频的音量。这可以用于例如,在锻炼应用程序中,假设用户正在跟着他们的 iPod 锻炼,而您的应用程序想要叠加一条口头消息,例如“您已经划船 10 分钟了”。为了确保应用程序中的消息易于理解,请将 kAudioSessionProperty_OtherMixableAudioShouldDuck 属性应用于音频会话。发生闪避时,设备上除手机音频之外的所有其他音频的音量都会降低。”

我认为这可能会降低。解决你的问题。关于初始化 AVAudioSession 以及设置其类别和属性的文档非常清晰且易于理解;你应该没有问题。

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

"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."

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文