Fix task cancellation bugs in MediaController, PlaybackController, and Recorder that could cause audio/media to resume during new recordings
This commit is contained in:
parent
0da24dc732
commit
a702199b56
@ -86,18 +86,23 @@ class MediaController: ObservableObject {
|
||||
let delay = audioResumptionDelay
|
||||
let shouldUnmute = didMuteAudio && !wasAudioMutedBeforeRecording
|
||||
|
||||
try? await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))
|
||||
let task = Task {
|
||||
try? await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))
|
||||
|
||||
if Task.isCancelled {
|
||||
return
|
||||
if Task.isCancelled {
|
||||
return
|
||||
}
|
||||
|
||||
if shouldUnmute {
|
||||
_ = executeAppleScript(command: "set volume without output muted")
|
||||
}
|
||||
|
||||
didMuteAudio = false
|
||||
currentMuteTask = nil
|
||||
}
|
||||
|
||||
if shouldUnmute {
|
||||
_ = executeAppleScript(command: "set volume without output muted")
|
||||
}
|
||||
|
||||
didMuteAudio = false
|
||||
currentMuteTask = nil
|
||||
unmuteTask = task
|
||||
await task.value
|
||||
}
|
||||
|
||||
private func executeAppleScript(command: String) -> Bool {
|
||||
|
||||
@ -108,13 +108,18 @@ class PlaybackController: ObservableObject {
|
||||
return
|
||||
}
|
||||
|
||||
try? await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))
|
||||
let task = Task {
|
||||
try? await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))
|
||||
|
||||
if Task.isCancelled {
|
||||
return
|
||||
if Task.isCancelled {
|
||||
return
|
||||
}
|
||||
|
||||
mediaController.play()
|
||||
}
|
||||
|
||||
mediaController.play()
|
||||
resumeTask = task
|
||||
await task.value
|
||||
}
|
||||
|
||||
private func isAppStillRunning(bundleId: String) -> Bool {
|
||||
|
||||
@ -213,6 +213,7 @@ class Recorder: NSObject, ObservableObject {
|
||||
deinit {
|
||||
audioLevelCheckTask?.cancel()
|
||||
audioMeterUpdateTask?.cancel()
|
||||
audioRestorationTask?.cancel()
|
||||
if let observer = deviceObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user