使用AVQueuePlayer时没有声音



我正在尝试播放两种声音,一种接另一种使用AVQueuePlayer,但两者都没有播放。我可以使用AVAudioPlayer单独播放它们。

这是我的队列播放器代码:

NSURL *hitURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/sfx_hit.wav", [[NSBundle mainBundle]resourcePath]]];
    NSURL *dieURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/sfx_die.wav", [[NSBundle mainBundle]resourcePath]]];
    AVPlayerItem *hit = [AVPlayerItem playerItemWithURL:hitURL];
    AVPlayerItem *die = [AVPlayerItem playerItemWithURL:dieURL];
    NSArray *playerItems = [NSArray arrayWithObjects:hit, die, nil];
    AVQueuePlayer *queuePlayer = [AVQueuePlayer queuePlayerWithItems:playerItems];
    [queuePlayer play];

我通过创建一个 queuePlayer 属性并像这样初始化它来修复它:

queuePlayer = [[AVQueuePlayer alloc]initWithItems:playerItems];

最新更新