0

我正在尝试使用以下代码在 iPad 中播放声音:

-(void)playSound:(NSString *)filename {
    SystemSoundID soundID;
    NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"wav"];    


    if (path) { 

        UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;    

        AudioSessionSetProperty (
                                 kAudioSessionProperty_AudioCategory,                        
                                 sizeof (sessionCategory),                                   
                                 &sessionCategory                                            
                                 );

        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID);
        AudioServicesPlaySystemSound (soundID);

    }
}

声音在模拟器中正常播放,但在真实设备上不起作用(不,它没有静音:-))

4

1 回答 1

0

检查文件扩展名是否区分大小写,是“WAV”还是“Wav”......而不是“wav”或者出于同样的原因检查您的文件名。

那可以解决你的问题。

于 2011-04-08T09:07:49.743 回答