I need your help. How should I proceed to change the sound volume in my app. I don’t want to use a volume slider. Instead I have an UIImageView which is a volume knob, in which I rotate clockwise to increase, and anti clockwise to decrease the sound volume. The rotation is just an animation and I’ve already done that part.
I need your help and advice on how to increase/decrease the volume. Thanks
I would be careful calling
setValueon anMPVolumeViewsince it probably won’t do anything other than update the appearance of the slider, but not the actual device volume level. You would instead have to call_commitVolumeChangewhich is private API and will likely get your app rejected.A short answer to how to control volume: It really depends on what you’re trying to control the volume of.
If you want a “controls every sound within the app” sort of control then you can use an
MPVolumeViewbut you cannot change it’s value programmatically. You would then only be able to change the volume by either moving the slider with a touch or using the volume buttons on the side of the device. The best thing to do is create a global object that stores the volume level which any of your objects can read before they play their sound.If it’s an
AVAudioPlayerobject, you’d create the object and use[theAudioPlayerObject setVolume: someFloat];wheresomeFloatis a value between 0.0 and 1.0.If it’s a
SystemSoundobject, you can’t control volume.If it’s an
AudioQueueyou’d change it viaAudioQueueSetParameterLike I said.. it all depends on how you are playing the sound.
Update based on comment
For that particular example, you would set the volume like this: