Ios 音频定时有问题

Ios 音频定时有问题,ios,audio,Ios,Audio,我的音频有问题 代码如下: AVAudioPlayer *audioPlayer; NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"Cheering" ofType:@"mp3"]; NSURL *audioURL = [NSURL fileURLWithPath:audioPath]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL

我的音频有问题

代码如下:

AVAudioPlayer *audioPlayer;
NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"Cheering" ofType:@"mp3"];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:nil];
[audioPlayer play];
它不会这样玩的。代码一步一步地完成,但没有音频。如果我在最后一行暂停,然后一步一步走过去,它就会正常播放。我已经尽我所能让它工作,但不知道从这里去哪里

它的行为好像在播放命令之前需要延迟。

您尝试过吗

[音频播放器准备播放]

在你真正尝试演奏之前


试试这个,确保它能起作用

NSURL* url = [[NSBundle mainBundle] URLForResource:@"Cheering" withExtension:@"mp3"];
NSAssert(url, @"URL is valid.");
NSError* error = nil;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
if(!audioPlayer)
{
    NSLog(@"Error creating player: %@", error);
}     else
{
    [audioPlayer play];
}

试过了,它也做了同样的事情