AVAudioPlayer eliminating one second pause between sound files

◇◆丶佛笑我妖孽 提交于 2019-12-13 00:29:05

问题


I am using multiple instances of AVAudioPlayer to play multiple sound files in a succession.

I am noticing that there is a roughly one second pause when two different sound files are played. Is it possible to eliminate this one second pause? I call [myPlayer prepareToPlay] for each player ahead of time already.


回答1:


According to AVAudioPlayer documentation you could use playAtTime: for synchronized playing.

Modified example would look like this:

- (void) startSynchronizedPlayback {

    NSTimeInterval shortStartDelay = 0.01;            // seconds
    NSTimeInterval now = player.deviceCurrentTime;

    [player       playAtTime: now + shortStartDelay];
    [secondPlayer playAtTime: now + shortStartDelay + player.duration];
}

I didn't test this but guess it should work. You should of course rename player and secondPlayer according to you names.



来源:https://stackoverflow.com/questions/11196345/avaudioplayer-eliminating-one-second-pause-between-sound-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!