我正在尝试使用以下代码在 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);
}
}
声音在模拟器中正常播放,但在真实设备上不起作用(不,它没有静音:-))