开发者

Adjust Volume in-App

开发者 https://www.devze.com 2023-02-14 23:06 出处:网络
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.

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!


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消