Reputation: 7900
i want in my app to increase and decrease the app volume programmatically from the code and not to use MPVolumeView.
Upvotes: 2
Views: 3252
Reputation: 16345
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.
Upvotes: 2
Reputation: 92424
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.
Upvotes: 3