ios监听音量按键
来源:互联网 发布:golang beego 编辑:程序博客网 时间:2024/06/05 09:40
这个很简单,KVO监听AVAudioSession单例的outputVolume属性值就可以了
[[AVAudioSession sharedInstance] addObserver:
self
forKeyPath:@
"outputVolume"
options:
NSKeyValueObservingOptionNew
|
NSKeyValueObservingOptionOld
context:(
void
*)[AVAudioSession sharedInstance]];
- (
void
)observeValueForKeyPath:(
NSString
*)keyPath ofObject:(
id
)object change:(
NSDictionary
*)change context:(
void
*)context{
if
(context == (__bridge
void
*)[AVAudioSession sharedInstance]){
float
newValue = [[change objectForKey:@
"new"
] floatValue];
float
oldValue = [[change objectForKey:@
"old"
] floatValue];
// TODO: 这里实现你的逻辑代码
}
}
设置按键音效
- (IBAction)DO:(id)sender{
soundFile = [NSStringstringWithFormat:@"/001.mp3"];
[selfplaySound: soundFile];
}
-(void)playSound:(NSString*)soundKey{
NSString *path = [NSStringstringWithFormat:@"%@%@",[[NSBundlemainBundle] resourcePath],soundKey];
//NSLog(@"%@\n", path);
SystemSoundID soundID;
NSURL *filePath = [NSURLfileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
}
0 0
- ios监听音量按键
- 如何监听音量按键
- 通过代码调整系统音量,监听音量实体按键事件
- iOS 监听音量调节 事件
- iOS 监听音量调节事件
- iOS监听音量调节事件
- iOS监听音量调节事件
- 获取系统当前音量 和 监听系统音量 ios
- ios监听app音量的变化
- iOS 监听App音量的变化
- iOS 监听App音量的变更
- iOS开发之:监听音量键
- iOS 监听和设置系统音量
- iOS如何拦截音量按键事件(前台+后台)
- iOS监听键盘的删除按键事件
- iOS监听键盘的删除按键事件
- ios监听静音键和音量键事件
- ios监听静音键和音量键事件
- 第十周项目 0 阅读程序(5)
- php 蒋中文首字母转换成拼音
- 大神学好网络经验谈
- 【python学习笔记一】
- t-分布邻域嵌入算法(t-SNE algorithm)简单理解
- ios监听音量按键
- 单元测试之Junit和spring集成
- Android 应用性能优化(二)高效使用内存
- hdu 5254 棋盘占领(百度之星2015初赛2 1003)暴力模拟
- javascript 网页跳转的方法
- dfs--查连通分量
- ORA-01078: failure in processing system parameters
- Hibernate的List映射
- ARM汇编中的:比较指令--CMN / CMP / TEQ / TST