在应用程序内调节音量
如何在我的应用程序中调整 iPhone 音量?有一种方法(潘多拉做到了),但我只是不知道该怎么做。
我主要需要能够将音量设置为最大,然后再将其设置为无。
有人有任何想法或教程吗?
提前致谢!
How can I adjust the iphone volume in my app? There is a way (pandora does it) but I just don't know how to.
I mainly need to be able to set the volume to max, and then set it to nothing later.
Does anyone have any ideas or tutorials?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在寻找一种允许用户在应用程序中控制音量的方法(Pandora 正在做的事情),那么您正在寻找 MPVolumeView。我自己使用过相同的控件,我 90% 确定这就是 Pandora 使用的控件。
If you're looking for a way to allow the user to control the volume while in your app, which is what Pandora is doing, you're looking for MPVolumeView. Having used the same control myself, I'm 90% sure that is what Pandora is using.
我正在寻找一种方法来为我的 MPMoviePlayerController 执行此操作,经过几天的搜索,结果发现这只是一行。
[[MPMusicPlayerController applicationMusicPlayer] setVolume:(使用 0.0 到 1.0 之间的值)]
问题是您的
MPMoviePlayerController
需要使用应用程序音频会话。请注意,根据我的测试,这仅适用于 MPMoviePlayerController - 我无法确定这对 AVAudioPlayers 等的影响。但无论如何它都值得一试。
编辑:哦,还有。这看起来有点老套 - 尽管这一切都归结为每个组件如何与应用程序音频会话交互,但我没有主动在
applicationMusicPlayer
上设置此类属性。设置它的音量属性也会影响我的 MPMoviePlayerController 是一个幸运的意外,而且确实没有办法确保这种行为在未来的版本中不会改变! /免责声明。I was looking for a way to do this for my MPMoviePlayerController, and after DAYS of searching, turns out it's just one line.
[[MPMusicPlayerController applicationMusicPlayer] setVolume:(use a value between 0.0 and 1.0)]
The catch being that your
MPMoviePlayerController
needs to be using the application audio session.Note that from my testing this works ONLY for MPMoviePlayerController - I cannot be certain about the effect this has on AVAudioPlayers etc. But it's worth a shot anyway.
Edit: Oh, also. It seems kinda hacky - although it all boils down to how each component interacts with the application audio session, I'm not ACTIVELY setting any property of that sort on the
applicationMusicPlayer
. That setting the volume property on it also influences my MPMoviePlayerController is a lucky accident, and there really is no way to be sure this behavior won't change in a future release! /Disclaimer.