Hardware Volume buttons change in app volume

谁说胖子不能爱 提交于 2020-01-01 19:21:13

问题


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


回答1:


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.




回答2:


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];


来源:https://stackoverflow.com/questions/14865317/hardware-volume-buttons-change-in-app-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!