嘿,我有几个AVAudioPlayers
每个包含一个声音。如果我多次按下相同的按钮,它应该从头开始重复声音。如果之后再按下另一个按钮,则应停止运行声音以便为新的“腾出空间”。iOS AVAudioPlayer再次播放声音
的代码我使用为:
-(void) plays:(int)p{ // p is the index of the sound being triggered
if([players[p] isPlaying])
{ // setting the time back to 0 makes
players[p].currentTime = 0.0; // the player automatically play again
}
else
{
[players[p] play]; // if not playing, start playing
}
if(last!=p)
{ // if the last sound is different from the current
[players[last] stop]; // stop the last one
players[last].currentTime = 0.0;} // put its position back to 0
last=p; // set the 'last' variable
}
然而,击中同一个按钮再次在没有听到声音稍微延迟(也许20毫秒)结束。现在是时候了,AVAudioPlayer
似乎需要“倒带”曲目才能再次播放。一个解决这个问题的想法是为每个声音创建AVAudioPlayer的多个对象,但这会产生一些糟糕的代码!关于如何使这个过程更快的任何想法?
谢谢,亚历克斯
编辑:玩2种不同的声音,工作完全正常,我不能在他们之间听到任何延迟,因为我prepareToPlay
所有事先声音。
感谢您的详细解答,我会为此付出努力。看起来我需要把自己看成AUGraph的东西:/也要感谢所有与音乐有关的输入,但我自己是一名制作人,我知道自己在做什么,但不幸的是,我在制作音乐方面比在编码方面做得更好哈哈 – user2875404