mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-26 02:05:19 +00:00
Display recording milliseconds
This commit is contained in:
@@ -68,6 +68,7 @@ struct ContentView: View {
|
|||||||
@State private var isPreparingVoiceNote = false
|
@State private var isPreparingVoiceNote = false
|
||||||
@State private var recordingDuration: TimeInterval = 0
|
@State private var recordingDuration: TimeInterval = 0
|
||||||
@State private var recordingTimer: Timer?
|
@State private var recordingTimer: Timer?
|
||||||
|
@State private var recordingStartDate: Date?
|
||||||
@State private var showImageImporter = false
|
@State private var showImageImporter = false
|
||||||
@State private var showFileImporter = false
|
@State private var showFileImporter = false
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@@ -1926,9 +1927,11 @@ private extension ContentView {
|
|||||||
|
|
||||||
func formattedRecordingDuration() -> String {
|
func formattedRecordingDuration() -> String {
|
||||||
let clamped = max(0, recordingDuration)
|
let clamped = max(0, recordingDuration)
|
||||||
let minutes = Int(clamped) / 60
|
let totalMilliseconds = Int((clamped * 1000).rounded())
|
||||||
let seconds = Int(clamped) % 60
|
let minutes = totalMilliseconds / 60_000
|
||||||
return String(format: "%02d:%02d", minutes, seconds)
|
let seconds = (totalMilliseconds % 60_000) / 1_000
|
||||||
|
let centiseconds = (totalMilliseconds % 1_000) / 10
|
||||||
|
return String(format: "%02d:%02d.%02d", minutes, seconds, centiseconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startVoiceRecording() {
|
func startVoiceRecording() {
|
||||||
@@ -1945,9 +1948,12 @@ private extension ContentView {
|
|||||||
do {
|
do {
|
||||||
_ = try VoiceRecorder.shared.startRecording()
|
_ = try VoiceRecorder.shared.startRecording()
|
||||||
recordingDuration = 0
|
recordingDuration = 0
|
||||||
|
recordingStartDate = Date()
|
||||||
recordingTimer?.invalidate()
|
recordingTimer?.invalidate()
|
||||||
recordingTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { _ in
|
recordingTimer = Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { _ in
|
||||||
recordingDuration += 0.1
|
if let start = recordingStartDate {
|
||||||
|
recordingDuration = Date().timeIntervalSince(start)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let timer = recordingTimer {
|
if let timer = recordingTimer {
|
||||||
RunLoop.main.add(timer, forMode: .common)
|
RunLoop.main.add(timer, forMode: .common)
|
||||||
@@ -1961,6 +1967,7 @@ private extension ContentView {
|
|||||||
VoiceRecorder.shared.cancelRecording()
|
VoiceRecorder.shared.cancelRecording()
|
||||||
isPreparingVoiceNote = false
|
isPreparingVoiceNote = false
|
||||||
isRecordingVoiceNote = false
|
isRecordingVoiceNote = false
|
||||||
|
recordingStartDate = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1975,6 +1982,10 @@ private extension ContentView {
|
|||||||
isRecordingVoiceNote = false
|
isRecordingVoiceNote = false
|
||||||
recordingTimer?.invalidate()
|
recordingTimer?.invalidate()
|
||||||
recordingTimer = nil
|
recordingTimer = nil
|
||||||
|
if let start = recordingStartDate {
|
||||||
|
recordingDuration = Date().timeIntervalSince(start)
|
||||||
|
}
|
||||||
|
recordingStartDate = nil
|
||||||
if send {
|
if send {
|
||||||
let minimumDuration: TimeInterval = 1.0
|
let minimumDuration: TimeInterval = 1.0
|
||||||
VoiceRecorder.shared.stopRecording { url in
|
VoiceRecorder.shared.stopRecording { url in
|
||||||
|
|||||||
Reference in New Issue
Block a user