获取系统当前音量 和 监听系统音量 ios
2013-02-23 17:57
1016 查看
-(float) getVolumeLevel {MPVolumeView*slide =[MPVolumeViewnew];UISlider*volumeViewSlider;for(UIView*view in[slide subviews]){if([[[view class] description] isEqualToString:@"MPVolumeSlider"]){ volumeViewSlider =(UISlider*) view;}}float val =[volumeViewSlider value];[slide release];return val;}
That should get you the current volume level. 1 is max volume, 0 is no volume. Note: no UI elements need to be displayed for this to work. Also note current volume level is relative to headphones or speakers (meaning, the two volume levels are different, and this gets you whichever the device is currently using. This doesn't answer your question regarding receiving notifications of when volume changes.
AVSystemController
+ (id)sharedAVSystemController;
- (void)getActiveCategoryVolume:(float*)outVolume andName:(NSString**)outName;
Returns the volumn and name of the active category. Tells you whether headphones are plugged in.
Notifications
Sends a AVSystemController_HeadphoneJackIsConnectedDidChangeNotification notification when the user plus in or unplugs headphones.
Sends a AVSystemController_SystemVolumeDidChangeNotification notification when the system volume has changed (via up/down buttons, mute switch, or programatically)
[[NSNotificationCenterdefaultCenter] addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
-(void)volumeChanged:(NSNotification *)notification { [volumeViewSlider setValue:[[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]]; }
-(void)volumeChanged:(NSNotification *)notification { [volumeViewSlider setValue:[[[notification userInfo] objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"] floatValue]]; }
相关文章推荐
- 获取系统当前音量 和 监听系统音量 ios
- iOS 获取当前日期和星期几,改变导航系统返回按钮的标题
- Swift3 获取系统音量和监听系统音量
- ios 首先获取系统当前时间:
- iOS开发-基础:获取系统当前日期,断点输出时间
- iOS 获取系统语言以及当前系…
- iOS获取当前系统的相关信息 - - 博客频道 - CSDN.NET (3)
- IOS 系统打电话事件的监听与状态获取
- ios获取当前系统的语言环境
- iOS获取系统当前时间
- IOS——地图的使用、地图定位到当前位置(包括ios8获取位置)、地图标注的添加、地图放大缩小监听
- iOS获取当前系统的相关信息
- ios获取系统当前日期,一定日期格式的代码
- ios 获取当前系统时间
- iOS开发 NSDate 获取系统当前时间
- iOS获取当前系统的相关信息和在不同的IOS上检测
- cocos2d-x在win32和iOS、android下获取当前系统时间的方法
- ios 获取当前系统时间
- iOS 系统提示框是否同意获取当前位置提示框自动消失
- ios之获取当前系统版本/UUID标识/名字/型号