我有以下代码,并且找到了 sound_file。我也没有错误。音频文件被添加到包中。但是我在 iOS 模拟器上没有声音。
- (void)playNotificationSound
{
NSString *sound_file;
AVAudioPlayer * audioPlayer;
sound_file = [[NSBundle mainBundle] pathForResource:@"onebell" ofType:@"caf"];
if (sound_file){
NSURL *url = [[NSURL alloc] initFileURLWithPath:sound_file];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
//audioPlayer.delegate = self;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
[audioPlayer play];
}
}