简体   繁体   English

(iphone) 如何使用 AVAudioPlayer 顺序播放声音?

[英](iphone) how to play sound sequentially with AVAudioPlayer?

I'd like to play multiple sound sequentially.我想顺序播放多个声音。
The sound data will be available via NSData.声音数据将通过 NSData 提供。
(to be more precise, I'm going to play different sound whenever scrollViewDidEndScrolling is called, and stop previous sound if it is still playing) (更准确地说,每当调用 scrollViewDidEndScrolling 时,我都会播放不同的声音,如果仍在播放,则停止之前的声音)

Do I need to alloc/init AVAudioPlayer for every sequential sound?我需要为每个连续的声音分配/初始化 AVAudioPlayer 吗?
If alloc/init/release AVAudioPlayer isn't a big deal, I could do that but I'm not sure如果 alloc/init/release AVAudioPlayer 没什么大不了的,我可以这样做,但我不确定

If using the higher-level AVAudioPlayer, then yes, you'd need to instantiate (alloc/init) an AVAudioPlayer for each.如果使用更高级别的 AVAudioPlayer,那么是的,您需要为每个实例化(alloc/init)一个 AVAudioPlayer。

Yet, the "expensive" part (time-wise) is prepareToPlay - which you could call in a separate thread, thus hopefully by the time you come to play any given sound, it will be fully ready to play.然而,“昂贵”的部分(时间方面)是 prepareToPlay - 您可以在单独的线程中调用它,因此希望在您播放任何给定的声音时,它会完全准备好播放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM