Sync Volume rocker with a UISlider

不羁的心 提交于 2019-12-08 10:32:44

问题


I am trying to get a UISlider to sync with the volume rocker. I have successfully used the slider to change the system/ringer volume, but I need the slider to move when the rocker moves. any suggestions on how to get the current volume value? I am using the code below to monnitor the volume change:

- (void)volumeChanged:(NSNotification *)notification{

       AVSystemController* avc = SharedAVSystemController;
       //   my sliders name is customVolume, and this is how I 
       //   am trying to get the volume:
       customVolume.value = [avc getVolume:(float *) forCategory:(id)];

}

Also, what are the AVSystemController categories other than "Ringtone"?


回答1:


There is a class available in the SDK which handles the system volume all by itself, MPVolumeView. It's not a subclass of UISlider therefore you can't change it's appearance (Well, it would be hard hacking it together all by yourself) but that's probably not an issue. (edit: looking at class dumps, the view contains a normal UISlider view so it may be easier than I expected)

I'm not sure whether it handles everything you need and if it will fit in your context, but you can also take a look at it and try it.




回答2:


This will update theUISliderwith the volume rocker:

- (void)volumeChanged:(NSNotification *)notification
{
    AVSystemController *avs = [ notification object ];
    NSString *audioDeviceName;
    [ avs getActiveCategoryVolume:&_volume andName:&audioDeviceName ];
}


来源:https://stackoverflow.com/questions/1971877/sync-volume-rocker-with-a-uislider

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