 
         let bufferOptions: AVAudioPlayerNodeBufferOptions = isLooping ? [.loops, .interrupts] : [.interrupts]
 
-        //AKLog("Scheduling buffer...\(startTime) to \(endTime)")
+        // AKLog("Scheduling buffer...\(startTime) to \(endTime)")
         if #available(iOS 11, macOS 10.13, tvOS 11, *) {
             playerNode.scheduleBuffer(buffer,
                                       at: audioTime,
                                       options: bufferOptions,
                                       completionCallbackType: .dataPlayedBack,
-                                      completionHandler: handleCallbackComplete)
+                                      completionHandler: completionHandler != nil ? handleCallbackComplete : nil)
         } else {
             // Fallback on earlier version
             playerNode.scheduleBuffer(buffer,

        let totalFrames = (audioFile.samplesCount - startFrame) - (audioFile.samplesCount - endFrame)
        frameCount = AVAudioFrameCount(totalFrames)

        //AKLog("startFrame: \(startFrame) frameCount: \(frameCount)")

        if #available(iOS 11, macOS 10.13, tvOS 11, *) {
            playerNode.scheduleSegment(audioFile,

                    gain = 1.0
                }

                // sanity check
                if gain > 1 {
                    gain = 1
                }
