iOS播放简短的音乐
2018-07-20 来源:open-open
这段代码能十分简单地播放简短的音效。在需要播放简单的声音文件,并且不需要重复播放时,可以使用这种方法。
#import <audiotoolbox audioservices.h="">
-(void) playSound : (NSString *) fName : (NSString *) ext
{
NSString *path = [[NSBundle *mainBundle] pathForResource : fName ofType :ext];
if ([[NSFileManager defaultManager] fileExistsAtPath : path])
{
NSURL *pathURL = [NSURL fileURLWithPath : path];
SystemSoundID audioEffect;
AudioServicesCreateSystemSoundID((CFURLRef) pathURL, &audioEffect;);
AudioServicesPlaySystemSound(audioEffect);
}
else
{
NSLog(@"error, file not found: %@", path);
}
//在非ARC模式下,还需要释放 audioEffect
AudioServicesDisposeSystemSoundID(audioEffect);
}
</audiotoolbox>
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
下一篇:java 解析XML文件
最新资讯
热门推荐