我有AVAudioPCMBuffer
,我将其设置为AVAudioPlayerNode
的源
internal func play() {
guard let buf = pcmBuf else {
logger?.log(severity: .error, msg: "Sound pcmBuf is nil.")
return
}
if !isPlaying {
player.scheduleBuffer(buf, at: nil, options: .loops)
player.play()
}
}
这是可能的用户查找向前,为了做到这一点,我需要偏移缓冲区并重新设置它,像这样
internal func play() {
guard let buf = pcmBuf else {
logger?.log(severity: .error, msg: "Sound pcmBuf is nil.")
return
}
buf.offset = 10 // Eg: in sec
if !isPlaying {
player.scheduleBuffer(buf, at: nil, options: .loops)
player.play()
}
}
所以,它看起来就像我设置了一个新的缓冲区,但是有了所需的偏移量,并且播放将从所需的点开始。
问题是没有offset
方法…
怎么做?
我认为你不需要偏移缓冲区。你应该给你的play函数传递一个有效的第二个参数,而不是nil。
https://developer.apple.com/documentation/avfaudio/avaudioplayernode/1388422-schedulebuffer
"在指定的时间和播放选项从音频缓冲区调度播放样本。">
所以传入一个有效的AVAudioTime
https://developer.apple.com/documentation/avfaudio/avaudioplayernode # 1669195
init(sampleTime: AVAudioFramePosition,
atRate sampleRate: Double)
我猜这可能是你想要的初始化器。