Fix AVFoundation failing to get the audio duration

This commit is contained in:
Beingpax 2025-08-14 19:54:19 +05:45
parent 36fa030d12
commit 87593ac243

View File

@ -279,7 +279,7 @@ class WhisperState: NSObject, ObservableObject {
}
let audioAsset = AVURLAsset(url: url)
let actualDuration = CMTimeGetSeconds(try await audioAsset.load(.duration))
let actualDuration = (try? CMTimeGetSeconds(await audioAsset.load(.duration))) ?? 0.0
var promptDetectionResult: PromptDetectionService.PromptDetectionResult? = nil
let originalText = text
@ -380,7 +380,7 @@ class WhisperState: NSObject, ObservableObject {
} catch {
do {
let audioAsset = AVURLAsset(url: url)
let duration = CMTimeGetSeconds(try await audioAsset.load(.duration))
let duration = (try? CMTimeGetSeconds(await audioAsset.load(.duration))) ?? 0.0
await MainActor.run {
let errorDescription = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription