From 28018e4e0dc84c5eb85b14dbbb864959b7ed3ff4 Mon Sep 17 00:00:00 2001 From: YuAo Date: Sat, 6 Mar 2021 17:13:27 +0800 Subject: [PATCH] add sampleWritingSessionStartedHandler to MultitrackMovieRecorder --- Sources/VideoIO/MultitrackMovieRecorder.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/VideoIO/MultitrackMovieRecorder.swift b/Sources/VideoIO/MultitrackMovieRecorder.swift index c75d98a..a3287bf 100644 --- a/Sources/VideoIO/MultitrackMovieRecorder.swift +++ b/Sources/VideoIO/MultitrackMovieRecorder.swift @@ -94,7 +94,18 @@ public final class MultitrackMovieRecorder { self.queue.sync { _duration } } - public var durationChangedHandler: ((CMTime) -> Void)? + public var sampleWritingSessionStartTime: CMTime? { + self.queue.sync { + if recordingStartSampleTime == .invalid { + return nil + } else { + return recordingStartSampleTime + } + } + } + + public var sampleWritingSessionStartedHandler: ((_ sampleWritingSessionStartTime: CMTime) -> Void)? + public var durationChangedHandler: ((_ duration: CMTime) -> Void)? private var lastVideoSampleTime: CMTime = .invalid private var recordingStartSampleTime: CMTime = .invalid @@ -189,6 +200,9 @@ public final class MultitrackMovieRecorder { self.assetWriter.startSession(atSourceTime: presentationTime) self.recordingStartSampleTime = presentationTime self.lastVideoSampleTime = presentationTime + DispatchQueue.main.async { + self.sampleWritingSessionStartedHandler?(presentationTime) + } } if self.assetWriter.status == .writing {