Reputation: 31
So in my app i would like to change the in app volume leves for an alarm by the use of the hardware buttons but whenever i use the buttons to turn up or down the volume it ONLY changes the "ringer" volume wich does NOT effect my in app volume.
Under Settings -> Sounds the "change with buttons" switch is ON and everything works fine if i turn it off but most users will want to have it on as well. So when im in my app i want the volume buttons to change the app volume not the ringer volume.
Hope it makes sense
Thanks
Upvotes: 1
Views: 1801
Reputation: 6667
Use MPVolumeView!
If you add an MPVolumeView
to your UIWindow
(you can make it hidden), the MPVolumeView
will automatically take over the hardware buttons for you. The hardware buttons will now affect your app's volume levels instead of the system's.
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectZero];
volumeView.showsRouteButton = NO;
volumeView.hidden = YES;
[self.window addSubview:volumeView];
Upvotes: 0
Reputation: 5552
By default the hardware buttons will change the alarm volume unless you have an open audio session when they use the buttons. I would recommend opening an AVAudioSession to have them change it or placing a volume slider somewhere in your app to have them change the volume.
This is a difficult problem to solve perfectly because users aren't told what is wrong and many times don't look to see that the ringer volume is what is being changed.
Upvotes: 3