使用System Sound Services 播放音效(最简单,比较底层),调用AudioServicesPlaySystemSound()
1、适用范围:一些很小的提示或警告音频。
2、使用限制:
声音长度不能超过30秒 声音文件必须是PCM或IMA4(IMA/ADPCM)格式。(有时候可播放一些特殊的.mp3) 打包成.caf、.aif或.wav文件 不能控制播放进度 调用方法后立即播放声音 没有循环播放和立体声播放控制。
3、AudioServicesPlaySystemSound()还可以调用系统的震动功能
4、可以用AudioServicesAddSystemSoundCompletion()函数增加CallBack函数来支持循环播放
5、播放音乐操作步骤
a、调用AudioServicesCreateSystemSoundID(CFURLRef inFileURL, SystemSoundID *outSystem SoundID)函数注册音频文件 b、若需要播放完成后进行某些操作,可调用AudiServicesAddSystemSoundCompletion()函数为指定的SoundID注册CallBack函数。 c、调用AudiServicesPlaySystemSound() // 播放音频 调用AudiServicesPlayAlertSound// 播放音频的同步调用系统的震动功能
6、代码演示
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h> static void completionCallback(SystemSoundID mySSID)
{
// 播放完毕之后,再次播放
AudioServicesPlaySystemSound(mySSID);
}
@implementation ViewController
SystemSoundID crash;
- (void)viewDidLoad
{
[super viewDidLoad];
// 定义要播放的音频文件的URL
NSURL* crashUrl = [[NSBundle mainBundle]
URLForResource:@"crash" withExtension:@"wav"];
// 加载音效文件
AudioServicesCreateSystemSoundID((__bridge CFURLRef)crashUrl , &crash);
// 为crash播放完成绑定回调函数
AudioServicesAddSystemSoundCompletion(crash, NULL, NULL,
(void*)completionCallback ,NULL);
}
- (IBAction)play:(id)sender {
// // 播放crash代表的音频
AudioServicesPlaySystemSound(crash);
// 播放crash代表的音频,并控制设备震动
// AudioServicesPlayAlertSound(crash);
}
@end
使用System Sound Services 播放音效(最简单,比较底层),调用AudioServicesPlaySystemSound()的更多相关文章
- iOS系统声音服务(System Sound Services)
系统声音服务(System Sound Services)提供了一个接口,用于播放不超过30秒的声音.它支持的文件格式有限,具体地说只有CAF.AIF和使用PCM或IMA/ADPCM数据的WAV文件. ...
- Audio播放音效
AudioToolbox.framework是一套基于C语言的框架,使用它来播放音效其本质是将短音频注册到系统声音服务(System Sound Service).System Sound Servi ...
- html5手机端播放音效不卡的方法
html5手机端播放音效不卡的方法线下载http://wxserver.knowway.cn/solosea/js/audioEngine.js 这个是性能不错 然后直接播放音效就可以了 audioE ...
- Android设备 cocos2dx 骨骼动画注册事件播放音效,退到后台再返回黑屏问题
最近遇到一个cocos2dx 骨骼动画注册事件播放音效,在骨骼动画播放的时候,按HOME键退到桌面,再次打开游戏的时候,会黑屏. 解决办法如下,可能不是太完美,至少解决了大部分问题. 1.在org.c ...
- arcgis server "System.Web.Services.Protocols.SoapException: Error processing server request".
在 Arcgis Server 10中创建第一个程序,运行的时候就报错:System.Web.Services.Protocols.SoapException: Error processing se ...
- C#、VB.NET 使用System.Media.SoundPlayer播放音乐
原文:C#.VB.NET 使用System.Media.SoundPlayer播放音乐 同步播放: System.Media.SoundPlayer player = new System.Media ...
- SpriteBuilder中时间线播放音效的弊端
当你美滋滋的在时间线中播放音效的时候,你要想到音效时间线并不适于播放同步于游戏事件的声音,比如碰撞和加速时. 它同样不能被用来播放背景循环的声音,这就本质上拒绝了通过timeline播放背景音乐.甚至 ...
- MessageBeep - Play a System sound
There is a interesting function which can play a System sound. First let's see the WinAPI. //声明: Mes ...
- cocos2dx AudioEngine在Android7上播放音效卡顿问题处理
1.此问题在cocos2dx 3.13/3.14版本(其它版本没有测试过)在Android7中使用AudioEngine的play2d函数播放音效时出现. 调试时出现如下提示: 2.论坛中相关讨论帖地 ...
随机推荐
- [转]FastJSON通过SerializeFilter定制序列化
原文地址:https://github.com/alibaba/fastjson/wiki/SerializeFilter 简介 SerializeFilter是通过编程扩展的方式定制序列化.fast ...
- iOS开发遇到的错误 -- Label显示多行文字导致宽度和高度的问题
Label的宽度问题 注意:UILabel下面需要设置preferredMaxLayoutWidth ,设置了autolayout和numberofline的UIlabel才显示多行 label宽度的 ...
- iOS开发小技巧--实现将图片保存到本地相册
一.报错的代码 错误 -- out of bounds 超出界限的意思 *** Terminating app due to uncaught exception 'NSInvalidArgument ...
- Linux_Shell_输出重定向
创建两个文件:touch 1 touch2 命令 > 文件 以覆盖的方式输出正确信息到文件或设备ls > 1 命令 >> 文件 以追加的方式输出正确信息到文件或设备l ...
- 查看本机ip
视窗+R 然后输入cmd, enter 后再黑色窗口里输入 ipconfig
- poi-处理excel的单元格日期数据
poi处理excel时,当excel没有明确指明是哪个类型的数据时,poi很可能处理单元格的日期数据时就有可能是一串数字.而使用java程序基本无法转换 以下为对poi处理日期情况一些方面的处理(不是 ...
- mindmup-editabletable-编辑table的使用
官方网站:http://mindmup.github.io/editable-table/ github下载地址:https://github.com/mindmup/editable-table 我 ...
- 【USACO 1.3】Barn Repair
贪心,去掉最大的min(m,c)-1个间隔 /******************************************* TASK: barn1 LANG: C++ Created Tim ...
- pycharm常用快捷键总结
http://blog.csdn.net/pipisorry/article/details/39909057 在PyCharm /opt/pycharm-3.4.1/help目录下可以找到Refer ...
- iOS随机生成数字
有时候我们需要在程序中生成随机数,但是在Objective-c中并没有提供相应的函数,好在C中提供了rand().srand().random().arc4random()几个函数.那么怎么使用呢?下 ...