2017-02-07 2 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 
    } 

}) 
에 대한 어떤 작업입니다