AVFoundation- 播放音效的例子

0、获取inSystemSoundID,并播放音效
使用AudioServicesCreateSystemSoundID加载音效。

** 使用全局的静态变量存储ID,保证只加载一次资源*/
+ (SystemSoundID)systemSoundIDWithFileName:(NSString *)fileName{
    SystemSoundID inSystemSoundID = [_inSystemSoundIDs[fileName] unsignedIntValue];
    if (inSystemSoundID ) {
        return inSystemSoundID;
    }
    CFURLRef inFileURL = (__bridge CFURLRef)([[NSBundle mainBundle] URLForResource:fileName withExtension:nil]);
    if (inFileURL == nil) {
        return 0;
    }
    //加载音效
    AudioServicesCreateSystemSoundID( inFi

你可能感兴趣的:(iOS,进阶,iOS开发基础)