Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Sources/VoiceMemo/AudioRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AudioRecorder: NSObject, ObservableObject, SCStreamOutput, SCStreamDelegat
@Published var availableApps: [SCRunningApplication] = []
@Published var selectedApp: SCRunningApplication?
@Published var latestTask: MeetingTask?
@Published var recordingDuration: TimeInterval = 0

var lastUploadedURL: URL? {
if let urlStr = latestTask?.ossUrl {
Expand All @@ -19,6 +20,7 @@ class AudioRecorder: NSObject, ObservableObject, SCStreamOutput, SCStreamDelegat
}

private var notificationObserver: NSObjectProtocol?
private var timer: Timer?

private var settings: SettingsStore
private var recordingId: String?
Expand Down Expand Up @@ -115,6 +117,14 @@ class AudioRecorder: NSObject, ObservableObject, SCStreamOutput, SCStreamDelegat
isFirstRemoteBuffer = true
isFirstMicBuffer = true
self.recordingStartTime = Date()
self.recordingDuration = 0

DispatchQueue.main.async {
self.timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
guard let self = self, let startTime = self.recordingStartTime else { return }
self.recordingDuration = Date().timeIntervalSince(startTime)
}
}

// Generate URLs
let formatter = DateFormatter()
Expand Down Expand Up @@ -323,6 +333,11 @@ class AudioRecorder: NSObject, ObservableObject, SCStreamOutput, SCStreamDelegat

func stopRecording() {
Task {
await MainActor.run {
self.timer?.invalidate()
self.timer = nil
}

settings.log("Stop recording")
// 1. Stop System Audio
try? await stream?.stopCapture()
Expand Down
11 changes: 10 additions & 1 deletion Sources/VoiceMemo/Views/RecordingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ struct RecordingView: View {
HStack(spacing: 8) {
Image(systemName: "stop.fill")
.font(.title3)
Text("Stop Recording")
Text("Stop Recording (\(formatDuration(recorder.recordingDuration)))")
.font(.headline)
.fontWeight(.bold)
.monospacedDigit()
}
.foregroundColor(.white)
.padding(.vertical, 10)
Expand Down Expand Up @@ -198,4 +199,12 @@ struct RecordingView: View {
}
.background(Color(nsColor: .windowBackgroundColor)) // Light gray background
}

private func formatDuration(_ duration: TimeInterval) -> String {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.minute, .second]
formatter.unitsStyle = .positional
formatter.zeroFormattingBehavior = .pad
return formatter.string(from: duration) ?? "00:00"
}
}