使用AVQueuePlayer时没有声音

时间:2014-02-25 19:34:30

标签: ios objective-c audio 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];

1 个答案:

答案 0 :(得分:0)

我通过创建一个queuePlayer属性并按如下方式初始化它来修复它:

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