|
|
|
|
@ -136,25 +136,26 @@ class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
|
|
|
|
|
let countdownId = countdown.stringId |
|
|
|
|
self._cleanupCurrentTimerIfNecessary(countdownId) |
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
let start = Date() |
|
|
|
|
let end = start.addingTimeInterval(countdown.duration) |
|
|
|
|
FileLogger.log("schedule countdown \(countdown.stringId) at \(end)") |
|
|
|
|
|
|
|
|
|
self.removeLiveTimer(id: countdown.stringId) |
|
|
|
|
FileLogger.log("schedule countdown \(countdownId) at \(end)") |
|
|
|
|
|
|
|
|
|
let sound = countdown.someSound |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdown.stringId, sound: sound) |
|
|
|
|
let soundPlayer = try DelaySoundPlayer(timerID: countdownId, sound: sound) |
|
|
|
|
|
|
|
|
|
FileLogger.log("a) self._delayedSoundPlayers count = \(self._delayedSoundPlayers.count)") |
|
|
|
|
self._delayedSoundPlayers[countdown.stringId] = soundPlayer |
|
|
|
|
self._delayedSoundPlayers[countdownId] = soundPlayer |
|
|
|
|
FileLogger.log("b) self._delayedSoundPlayers count = \(self._delayedSoundPlayers.count)") |
|
|
|
|
|
|
|
|
|
try soundPlayer.start(in: countdown.duration, |
|
|
|
|
repeatCount: Int(countdown.repeatCount)) |
|
|
|
|
|
|
|
|
|
let dateInterval = DateInterval(start: start, end: end) |
|
|
|
|
self.currentCountdowns[countdown.stringId] = dateInterval |
|
|
|
|
self.currentCountdowns[countdownId] = dateInterval |
|
|
|
|
|
|
|
|
|
if Preferences.playConfirmationSound { |
|
|
|
|
self._playConfirmationSound(timer: countdown) |
|
|
|
|
@ -170,6 +171,13 @@ class Conductor: ObservableObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _cleanupCurrentTimerIfNecessary(_ timerId: TimerID) { |
|
|
|
|
self.removeLiveTimer(id: timerId) |
|
|
|
|
if let player = self._delayedSoundPlayers[timerId] { |
|
|
|
|
player.stop() // release resources |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func cancelCountdown(id: TimerID) { |
|
|
|
|
|
|
|
|
|
FileLogger.log("Cancel \(id)") |
|
|
|
|
|