iPhone-同时启动AVAudioPlayer的多个实例 [英] iPhone - start multiple instances of AVAudioPlayer simultaneously

查看:139
本文介绍了iPhone-同时启动AVAudioPlayer的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVAudioPlayer的多个实例来同时播放多个音频文件.我运行一个循环以开始播放音频文件(预先调用了prepareToPlay,并且该循环仅调用play方法)

I am using multiple instances of AVAudioPlayer to play multiple audio files simultaneously. I run a loop to start playing the audio files (prepareToPlay is called beforehand and the loop only makes a call to the play method)

但总是有一位球员没有同步比赛.如何确保所有4个播放器同时开始播放音频?

But invariably, one of the players does not play in sync. How can I ensure that all the 4 players start playing audio simultaneously?

谢谢.

推荐答案

很遗憾,您不能这样做. AVAudioPlayer没有提供任何用于开始时间的细粒度控制的机制. currentTime属性设置文件中要读取的点,它不能保证AVAudioPlayer实例何时在系统时间开始播放,这是同步多个音频流所需要的.

Unfortunately, you can't. AVAudioPlayer doesn't provide any mechanism for fine-grained control of start time. The currentTime property sets the point in the file to read from, it doesn't guarantee when the AVAudioPlayer instance will start playing in system time, which is what you need to sync multiple audio streams.

当我需要这种行为时,我将使用RemoteIO音频单元+ 3D混合器音频单元+ ExtAudioFile.

When I need this behavior, I use the RemoteIO Audio Unit + the 3D Mixer Audio Unit + ExtAudioFile.

编辑

请注意,从iOS 4开始,您可以使用playAtTime:

Note that as of iOS 4, you can synchronize multiple AVAudioPlayer instances using playAtTime:

这篇关于iPhone-同时启动AVAudioPlayer的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆