在iPad上播放声音,使用AudioToolbox



我发现了一个使用工具箱播放声音的函数,功劳归于创建它的人:

-(SystemSoundID) createSoundID: (NSString*)name {
    NSString *path = [NSString stringWithFormat: @"%@/%@",
             [[NSBundle mainBundle] resourcePath], name];
    NSURL* filePath = [NSURL fileURLWithPath: path isDirectory: NO];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
    NSLog(@"%@, %@", path, filePath);
    return soundID;
}

但是当我想要播放声音时,我使用了

函数
mySound = [self createSoundID: @"canopen.wav"];
AudioServicesPlaySystemSound(mySound);

它只在模拟器中播放,一旦我把它移到iPad上就不会播放了。请帮助

同样的事情前段时间也发生在我身上。检查你的iPad是否静音:)

最新更新