循环播放系统提示音
来源:互联网 发布:淘宝美工遇到的问题 编辑:程序博客网 时间:2024/05/16 03:20
苹果设备中经常要用到提示声音,提示声音最好用SystemSoundID,因为可以根据系统设置自动识别是否在播放声音的时候振动。这里演示的是循环播放提示声音:
- (void)playAlarmSound { NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:type]; //组装并播放音效 SystemSoundID soundID; NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); self.soundId = soundID;// 生成的soundID要用全局变量保存,循环播放要用到。 if(IOS9){// ios9以上调用此方法 [self playIOS9LaterConsecutivelyAlarmSoundId:soundID]; }else { [self playIOS9BeforeConsecutivelyAlarmSound]; }}// iOS9以后持续播放声音- (void)playIOS9LaterConsecutivelyAlarmSoundId:(SystemSoundID)soundID{ DLog(@"开始播放 soundID = %d",soundID); if (soundID == 0) { return; } AudioServicesPlaySystemSoundWithCompletion(soundID, ^{ if (!self.stopSoundAndVibrate) {// 播放结束判断是否已经点击停止// 当播放一便结束之后再次调用该方法 [self playIOS9LaterConsecutivelyAlarmSoundId:self.soundId]; }else { [self stopSystemSound]; } });}/********************ios9 之前调用的方法********************/- (void)playIOS9BeforeConsecutivelyAlarmSound{ // soundCompletionCallback 播放完成的回调 AudioServicesAddSystemSoundCompletion(self.soundId, NULL, NULL,soundCompletionCallback , NULL); AudioServicesPlaySystemSound(self.soundId);}// iOS9以前持续播放声音static void soundCompletionCallback (SystemSoundID soundID,void* sample) { AudioServicesPlaySystemSound(soundID);//循环播放}// 停止报警声跟振动- (void)stopSystemSound { self.stopSoundAndVibrate = YES; AudioServicesRemoveSystemSoundCompletion(kSystemSoundID_Vibrate); AudioServicesRemoveSystemSoundCompletion(self.soundId); AudioServicesDisposeSystemSoundID(kSystemSoundID_Vibrate); AudioServicesDisposeSystemSoundID(self.soundId); self.soundId = 0;}
阅读全文
0 0
- 循环播放系统提示音
- iOS播放系统提示音
- Android 播放系统提示音
- 简单播放系统提示音 android
- iOS 播放系统提示音和使用系统方法播放本地提示音
- java播放提示音
- html播放提示音
- android 播放提示音
- 【Android】播放提示音
- Android 播放提示音
- 播放音乐提示音
- iOS播放提示音
- 播放提示音
- Cocos2dx-lua 播放音循环播放问题
- JQuery自动播放提示音
- HTML中播放提示音
- iOS开发小结 - 播放系统提示音使用总结(AudioToolbox)
- usb插拔提示音播放
- 课后作业之学生类
- 类 小组成员
- Ubuntu lsof 命令整理
- 一分钟教你知道乐观锁和悲观锁的区别
- 同花顺函数API
- 循环播放系统提示音
- Java分布式应用技术架构介绍
- ES 2.4 java API aggregation API
- BZOJ 4401: 块的计数
- linux 安装jdk9
- Shuffle原理剖析与源码分析
- unity socket 服务器sever 代码
- 交易软件
- tomcat下发布多个项目报错webAppKey重复设置