i want in my app to increase and decrease the app volume programmatically from the code and not to use MPVolumeView.
-
If you want to change the volume without the user's permission/intervention, I don't think that is possible. – Akshay Aug 21 '11 at 12:22
2 Answers
You cannot change the volume programmatically, and that's a deliberate design choice. Imagine an app that constantly sets the volume to the highest level, that would not only be annoying but could even damage your ears if you're wearing in-ear headphones.
You should show an MPVolumeView to the user so he can change the volume himself. You can walk its subview hierarchy and search for the UISlider
and adjust its appearance like with any normal UISlider. This way you can adapt the MPVolumeView
to your app design.

- 90,870
- 19
- 190
- 224
Officially: You can't.
If you really want to do so, link against Celestial.framework
and use its controllers to change the volume - that is how SpringBoard and friends do it. I don't remember how to do it, but with a bit of research you should be able to find the answer. This will get your app rejected. If you're developing for a jailbroken device, this is the way to go.
If you want to go deeper you can do it via the vTable of the appropriate CoreAudio
service. You also need Celestial.framework
for that. And if you want to go even deeper, kill mediaserver
and make your own implementation which should occupy your for the next few months.

- 15,859
- 29
- 111
- 181