2017-02-07 44 views

回答

0

我能想到的是重新安排相同緩衝,每次提供一個完成處理程序的唯一方法。

我會去這樣的:

func scheduleNext() { 
    self.audioPlayerNode.scheduleBuffer(buffer, at: nil, completionHandler: completionHandler) 
} 

func completionHandler() { 
    // code here 

    scheduleNext() 
} 

// ... 
scheduleNext() 
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 
    } 

}) 
哪些工作