 //  Copyright © 2017 Audive Inc. All rights reserved.
 //
 
-/// A closure that will be called when the clip is finished recording. If
-/// successful URL will be non-nil. If recording failed, Error will be non nil.  The actual
-/// start time is included and should be checked in case it was adjusted.
-public typealias AKRecordingResult = (URL?, Double, Error?) -> Void
+/// A closure that will be called when the clip is finished recording.
+/// Result will be an error or a clip. ClipRecording.url is the location
+/// of the recording in the temporary diretory, it should be moved or copied
+/// from this location within this closure, it will be deleted after.
+/// startTime and duration may be different than parameters given in recordClip().
+///
+public typealias ClipRecordingCompletion = (ClipRecordingResult) -> Void
+
+public struct ClipRecording {
+    var url: URL
+    var startTime: Double
+    var duration: Double
+}
+public enum ClipRecordingResult {
+    case clip(ClipRecording)
+    case error(Error)
+}
 
 open class AKClipRecorder {
 

    ///   - duration: The duration in seconds of the clip to record, will be adjusted if start time
    /// was adjusted.
    ///   - tap: An optional tap to access audio as it's being recorded.
    ///   - completion: A closure that will be called when the clip is finished recording. If
    /// successful URL will be non-nil. If recording failed, Error will be non nil.  The actual
    /// start time is included and should be checked in case it was adjusted.
    ///
    public func recordClip(time: Double = 0,
                           duration: Double = Double.greatestFiniteMagnitude,
                           tap: AVAudioNodeTapBlock? = nil,
                           completion: @escaping AKRecordingResult) throws {

        guard time >= 0, duration > 0, time + duration > timing.currentTime else {
            throw ClipRecordingError.invalidParameters

        if clip.audioTimeStart != nil,
            let audioFile = clip.audioFile,
            audioFile.length > 0 {
            let duration = audioFile.duration
            clip.audioFile = nil
            clip.completion(ClipRecordingResult.clip(ClipRecording(url: url, startTime: clip.startTime, duration: duration)))
            completion?()
        } else {
            clip.completion(ClipRecordingResult.error(error ?? ClipRecordingError.timingError))
            completion?()
        }
        if FileManager.default.fileExists(atPath: url.path) {
