2

バッファをスケジュールするときに各ループの完了ハンドラを持つ方法はありますか?

self.audioPlayerNode.scheduleBuffer(buffer, at: nil, options: .loops, completionHandler: completionHandler)

// call each loop, not only on the buffer end
func completionHandler() {
    // code here
}
4

2 に答える 2

0

ここに私のために働くものがあります

// audioFile here is our original audio

audioPlayerNode.scheduleFile(audioFile, at: nil, completionHandler: {
        print("scheduleFile Complete")

    var delayInSeconds: Double = 0

    if let lastRenderTime = self.audioPlayerNode.lastRenderTime, let playerTime = self.audioPlayerNode.playerTime(forNodeTime: lastRenderTime) {

        if let rate = rate {
            delayInSeconds = Double(audioFile.length - playerTime.sampleTime) / Double(audioFile.processingFormat.sampleRate) / Double(rate!)
        } else {
            delayInSeconds = Double(audioFile.length - playerTime.sampleTime) / Double(audioFile.processingFormat.sampleRate)
        }
    }

    // schedule a stop timer for when audio finishes playing
    DispatchTime.executeAfter(seconds: delayInSeconds) {
        audioEngine.mainMixerNode.removeTap(onBus: 0)
        // Playback has completed
    }

})
于 2018-02-08T06:32:18.197 に答える