我希望根据按下的按钮在我的 iPhone (iOS 6.1) 上播放声音。
在转换为 aif、caf、wav 和压缩格式后,我无法在设备上听到声音。已检查音量,已重新启动设备,文件名中不包含大写字母。
我阅读了很多关于这个问题的主题,但找不到合适的解决方案,这意味着我的问题要么更复杂,要么很愚蠢——当然很愚蠢。
这是我播放声音的代码:
// Plays sound of given filename
- (void) playSound:(NSString*)name {
    SystemSoundID sound = [self createSoundID:name];
    AudioServicesPlaySystemSound(sound);
    NSLog(@"file played: %@",name);
}
// Creates a playable sound out of filename
-(SystemSoundID) createSoundID:(NSString*) name
{
    NSString *path = [NSString stringWithFormat: @"%@/%@",
                      [[NSBundle mainBundle] resourcePath], name];
    NSURL* filePath = [NSURL fileURLWithPath: path isDirectory: NO];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
    return soundID;
}