【问题标题】:AVQueuePlayer not playing soundsAVQueuePlayer 不播放声音
【发布时间】:2012-05-16 17:15:02
【问题描述】:

我似乎无法使用AVQueuePlayer 播放声音。应用程序编译并运行良好,但在调用 `imageTouched' 方法时我没有收到任何音频。有人可以帮忙吗?

-(void) imageTouched
{
    NSString * path1 = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
    NSString * path2 = [[NSBundle mainBundle] pathForResource:@"sound2" ofType:@"wav"];
    NSURL *url1 = [NSURL fileURLWithPath:path1];
    NSURL *url2 = [NSURL fileURLWithPath:path2];

    AVPlayerItem *firstSound = [AVPlayerItem playerItemWithURL:url1];
    AVPlayerItem *secondSound = [AVPlayerItem playerItemWithURL:url2];

    NSArray *sounds = [NSArray arrayWithObjects:firstSound, secondSound, nil];
    AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:sounds];

    [player play];
    NSLog(@"%d",player.status);

}

编辑 1: 我检查了文件名(大小写、拼写等)是否有任何问题,但似乎没有。我已经能够使用以下代码播放声音,但我真的需要让AVQueuePlayer 工作。请帮忙!

NSString *path;
SystemSoundID soundId;
path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer( url), &soundId);
AudioServicesPlaySystemSound(soundId);

【问题讨论】:

  • 检查声音文件是否实际包含在您的应用程序包中,并且它们的文件名拼写正确(包括大小写)。
  • 声音复制到我的资源文件夹,拼写正确;不幸的是,这不是问题。如果有任何帮助,我的 nslog 正在打印 0
  • 我还应该提到我可以使用AudioServicesPlaySystemSound(soundId); 很好地播放声音,但我想使用AVQueuePlayer。我的 .h 文件中是否可能缺少某些内容?

标签: iphone ios ipad audio avqueueplayer


【解决方案1】:

我意识到现在对你来说可能为时已晚,但我怀疑原因是 AVQueuePlayer 正在立即自动释放,所以没有播放声音。请改用[[AVQueuePlayer alloc] initWithItems:sounds]

【讨论】:

    【解决方案2】:

    我的想法几乎相同,但我没有在函数中声明 AVQueuePlayer *player,而是在 interface 中声明了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 2011-02-25
      • 2020-02-15
      • 2015-12-22
      • 2022-01-25
      • 1970-01-01
      相关资源
      最近更新 更多