gpt4 book ai didi

swift - 同步多个 AKPlayer

转载 作者:搜寻专家 更新时间:2023-10-31 23:07:37 24 4
gpt4 key购买 nike

我已经为此苦苦挣扎了一段时间。我有一系列 AKPlayer。

var players = [AKPlayer]()

我在网上搜索了很多关于同一问题的其他问题,他们都建议使用:AKPlayer.play(atTime: AVAudioTime)

我已经尝试过(以及其他类似的尝试):

    var sampleRate = selectedSong!.channels[0].audioFile!.sampleRate
var sampleTime = players[0].audioTime(at: players[0].currentTime)?.sampleTime
var startTime = AVAudioTime(sampleTime: sampleTime! + Int64(0.25*sampleRate), atRate: sampleRate)

for audioPlayer in players {
audioPlayer.play(at: startTime)
}

和其他类似的东西,比如:

 for audioPlayer in players {
audioPlayer.play(when: 0, hostTime: mach_absolute_time())
}

但它们都不起作用。播放时间之间存在明显差异。 (音频文件的长度相同,格式相同)。

如果有帮助,我的设置如下:

AKPlayer -> AKPitchShifter 
> AKMixer > AudioKit.output
AKPlayer

** 上面的所有 AKPlayer 都附加到 players 数组。

可能是因为我对AVAudioTime 是什么以及它是如何工作的缺乏了解。

提前致谢。

******* 注意事项 ******docs对于 AKPlayer

Players can be locked to a common clock as well as video by using hostTime in the various play functions

但是没有提供同步到hostTime的例子。

最佳答案

您走在正确的轨道上。您只需要获取当前时间,而不是使用 audioTime(at:) 检索它,这仅对已经播放的播放器有用。

// .now() is a convenience extension and AVAudioTime + Double is overloaded.
var startTime = AVAudioTime.now() + 0.25

如果任意 0.25 缓冲区没有削减它,请尝试循环播放调用 player.prepare() 的播放器,然后再获取 now() 以开始安排。

关于swift - 同步多个 AKPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48956626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com