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

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

问题描述

我在iOS中发现了一些有关播放声音的相互矛盾的数据。我想知道是否有人可以指出我每次用户触摸屏幕时只播放一个简单的ping声音的最佳方式。

Im finding a number of conflicting data about playing sounds in iOS. I was wondering if anyone could point me to the best 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天全站免登陆