ios - 使用AVQueuePlayer时无声音

标签 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];

最佳答案

我通过创建queuePlayer属性并初始化如下来修复它:

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

关于ios - 使用AVQueuePlayer时无声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22024373/

相关文章:

iOS延迟更改背景颜色(快速)

objective-c - 如何按字母顺序对 NSArray 进行排序?

ios - 你怎么能让 uilabel 环绕图像(如图所示)

ios - NSOperationQueue 中的 dispatch_after 等价物

android - 如何通过单击手机侧面的上下按钮来禁用关闭声音?

iphone - 为什么 CLLocationManager 总是返回 true?

ios - Soundcloud应用程序支持共享吗?

iphone - 将触摸事件传递给 iOS 状态栏

android - MediaCodec - 从 48k Hz 到 44.1k Hz 的下采样音频仍以较慢的速度播放

android - Android下Phonegap中的SoundCloud Stream