Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Iphone中同步播放两个或多个AVAudioPlayer_Iphone_Objective C_Synchronization_Avaudioplayer - Fatal编程技术网

在Iphone中同步播放两个或多个AVAudioPlayer

在Iphone中同步播放两个或多个AVAudioPlayer,iphone,objective-c,synchronization,avaudioplayer,Iphone,Objective C,Synchronization,Avaudioplayer,我需要在同一时间用2个AVAudioPlayer对象播放2个声音。。。所以我在Apple AVAudioPlayer类参考中找到了这个示例(https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html): 我不明白的是:为什么第二个玩家也有shorStartDelay? 它不应该没有吗?我认为第一个

我需要在同一时间用2个AVAudioPlayer对象播放2个声音。。。所以我在Apple AVAudioPlayer类参考中找到了这个示例(https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html):

我不明白的是:为什么第二个玩家也有shorStartDelay? 它不应该没有吗?我认为第一个玩家需要0.1秒的延迟,因为在第二个玩家之前。。。但是在这个代码中,两个玩家有延迟。。。 任何人都可以向我解释这是否正确,为什么? 谢谢
Massy

如果只使用播放方法([firstPlayer play];),firstPlayer将在第二个播放方法之前启动,因为它将在第二个播放方法之前接收调用

如果不设置延迟([firstPlayer PlayaTime:now];),firstPlayer也将在de second one之前启动,因为firstPlayer将检查它应该启动的时间,并将看到它已经过了。因此,它将具有与仅使用play方法时相同的行为

延迟是为了确保两名球员同时开始比赛。它应该足够长,以确保两名玩家在“现在+延迟”时间过去之前收到呼叫


我不知道我是否清楚(英语不是我的母语)。如果您有问题,我可以试着说得更清楚些。如果您只使用play方法([firstPlayer play];),firstPlayer将在第二个之前启动,因为它将在之前接收呼叫

如果不设置延迟([firstPlayer PlayaTime:now];),firstPlayer也将在de second one之前启动,因为firstPlayer将检查它应该启动的时间,并将看到它已经过了。因此,它将具有与仅使用play方法时相同的行为

延迟是为了确保两名球员同时开始比赛。它应该足够长,以确保两名玩家在“现在+延迟”时间过去之前收到呼叫

我不知道我是否清楚(英语不是我的母语)。如果你有问题的话,我可以说得更清楚一些

- (void) startSynchronizedPlayback {



NSTimeInterval shortStartDelay = 0.01;            // seconds

NSTimeInterval now = player.deviceCurrentTime;



[player       playAtTime: now + shortStartDelay];

[secondPlayer playAtTime: now + shortStartDelay];



// Here, update state and user interface for each player, as appropriate

}