问题
I'm silencing the iPhone ringer with AVSystemController, but I don't know how to determine the current level of the ringer. Any ideas?
PS Yes I know that using AVSystemController might get the app banned from the App Store. It's not an issue.
回答1:
You cannot change device volume programatically, however MPVolumeView (volume slider) is there to change device volume but only through user interaction, like making your own slider and labeling it 'volume' or something.
MPVolumeView is a control in toolbox, you need to add MediaPlayer.framework in your project then MPVolumeView will be displayed in toolbox in interface builder. MPVolumeView uses device volume, including ringing volume. AVAudioPlayer is only for application level volume.
Also, there is a little thing you can do:
musicPlayer = [[MPMusicPlayerController iPodMusicPlayer];
musicPlayer.volume = 1; // device volume will be changed to maximum value
Hope this helps.
来源:https://stackoverflow.com/questions/7946246/how-to-determine-the-current-level-of-the-iphone-ringer