标签:
很简单的调用
首先在工程引入MediaPlayer.framework
#import <MediaPlayer/MediaPlayer.h>
1. 获取系统音量
// 获取系统音量
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
UISlider *volumeViewSlider= nil;
for (UIView *view in [volumeView subviews]){
if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
volumeViewSlider = (UISlider*)view;
break;
}
}
float systemVolume = volumeViewSlider.value;
2.监听方法
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volumeChanged:) name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
- (void)volumeChanged:(NSNotification *)notification
{
[notification.userInfo[@"AVSystemController_AudioVolumeNotificationParameter"] floatValue];
}
3.记得销毁哦
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"AVSystemController_SystemVolumeDidChangeNotification" object:nil];
}
标签:
原文地址:http://www.cnblogs.com/Milo-CTO/p/4581662.html