[绍棠] 播放器检测系统音量键调节音量的变化并自定义音量界面
来源:互联网 发布:房产端口是什么意思 编辑:程序博客网 时间:2024/04/30 22:59
在viewdidload中新增一个音量视图替换掉系统的音量视图
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
volumeView.center = CGPointMake(-550,370);//设置中心点,让音量视图不显示在屏幕中
[volumeView sizeToFit];
[self.view addSubview:volumeView];
到此监听音量调节事件就搞定了
添加监听
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(volumeChanged:)name:@"AVSystemController_SystemVolumeDidChangeNotification"object:nil];
方法处理
- (void)volumeChanged:(NSNotification *)notification {
float volume = [[[notificationuserInfo]objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
}
/// 注意, 该消息除了监听音量键之外,应用从后台切换到前台也会发送该消息,所以,还需要判断消息的userInfo的字段AVSystemController_AudioVolumeChangeReasonNotificationParameter,确定发送消息的理由,value值为ExplicitVolumeChange就是我们所需要的。
- (void)volumeChanged:(NSNotification *)notification {
if ([notification.nameisEqualToString:@"AVSystemController_SystemVolumeDidChangeNotification"]) {
NSDictionary *userInfo = notification.userInfo;
NSString *reasonStr = userInfo[@"AVSystemController_AudioVolumeChangeReasonNotificationParameter"];
if ([reasonStrisEqualToString:@"ExplicitVolumeChange"]) {
float volume = [[[notificationuserInfo]objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]floatValue];
}
}
}
销毁
- (void)dealloc{
DDLogInfo(@"%@ is dealloc",self);
[NSObjectcancelPreviousPerformRequestsWithTarget:self];
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"AVSystemController_SystemVolumeDidChangeNotification"object:nil];
[[NSNotificationCenterdefaultCenter]removeObserver:self];
}
- [绍棠] 播放器检测系统音量键调节音量的变化并自定义音量界面
- 播放音乐并调节音量
- 拦截音量键调节音量
- 调节IOS系统的音量
- IOS音量调节--隐藏系统音量调节
- 自定义View音量调节
- Android自定义音量调节
- android 音量调节以及媒体音量界面
- android 音量调节以及媒体音量界面
- Android中自定义SeekBar来控制音量,并与系统音量键的操作保持同步
- 【Android界面实现】自定义音量调节控件的实现
- 调节系统音量(话筒)
- ios 调节系统音量
- MFC音乐播放器音量调节失效
- 调节ubuntu的音量
- 使用AudioManager调节播放器音量的开发实例
- 一键调节音量
- 音量调节
- 日期、时间选择器
- 三个代码块
- seajs添加版本号刷新本地缓存的方法
- leetcode-33. Search in Rotated Sorted Array
- Bootstrap3 排版-列表
- [绍棠] 播放器检测系统音量键调节音量的变化并自定义音量界面
- iOS nil 的小说明
- 多个checkbook默认选中
- PhotoView源码初始化BUG修复
- github添加ssh key的时候报错:Key is invalid. Ensure you've copied the file correctly
- eclipse程序正确但是cannot be resolved to a type
- 通过unix系统底层获取和系统相关的硬件信息(cpu、内存)
- 关于git的一些常用命令
- MySQL数据库备份脚本