在iOS中播放简单音效的最佳方法 [英] Best ways to play simple sound effect in iOS

查看:309
本文介绍了在iOS中播放简单音效的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现许多有关在iOS中播放声音的冲突数据.建议在用户每次触摸屏幕时仅播放简单的"ping"声音叮咬的方法是什么?

I'm finding a number of conflicting data about playing sounds in iOS. What is a recommended way to play just a simple "ping" sound bite every time the user touches the screen?

推荐答案

这是在iOS中播放简单声音(不超过30秒)的最佳方法:

This is the best way of playing a simple sound in iOS (no more than 30 seconds):

//Retrieve audio file
NSString *path  = [[NSBundle mainBundle] pathForResource:@"soundeffect" ofType:@"m4a"];
NSURL *pathURL = [NSURL fileURLWithPath : path];

SystemSoundID audioEffect;
AudioServicesCreateSystemSoundID((__bridge CFURLRef) pathURL, &audioEffect);
AudioServicesPlaySystemSound(audioEffect);

// call the following function when the sound is no longer used
// (must be done AFTER the sound is done playing)
AudioServicesDisposeSystemSoundID(audioEffect);

这篇关于在iOS中播放简单音效的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆