From 977c44eb05cf20da5a9fbcee90987dd5b0248cbf Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 29 Nov 2023 10:16:23 +0100 Subject: [PATCH] Fixes repeating sound --- LeCountdown/Conductor.swift | 5 ++--- LeCountdown/Sound/DelaySoundPlayer.swift | 12 ++++++------ LeCountdown/Sound/Sound.swift | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/LeCountdown/Conductor.swift b/LeCountdown/Conductor.swift index eb9a7c1..6b647f4 100644 --- a/LeCountdown/Conductor.swift +++ b/LeCountdown/Conductor.swift @@ -260,8 +260,7 @@ class Conductor: ObservableObject { let soundPlayer = try DelaySoundPlayer(sound: sound) self._delayedSoundPlayers[playerId] = soundPlayer - try soundPlayer.start(in: interval, - repeatCount: Int(countdown.repeatCount)) + try soundPlayer.start(in: interval) return end } @@ -427,7 +426,7 @@ class Conductor: ObservableObject { self.cleanupLiveActivities() } } - + fileprivate func _cleanupCountdowns() { let now = Date() for (key, value) in self.currentCountdowns { diff --git a/LeCountdown/Sound/DelaySoundPlayer.swift b/LeCountdown/Sound/DelaySoundPlayer.swift index 7aee07c..3090f92 100644 --- a/LeCountdown/Sound/DelaySoundPlayer.swift +++ b/LeCountdown/Sound/DelaySoundPlayer.swift @@ -28,23 +28,23 @@ import AVFoundation self._player = try AVAudioPlayer(contentsOf: url) } - func restore(for playDate: Date, repeatCount: Int) throws { + func restore(for playDate: Date) throws { let timeLeft = playDate.timeIntervalSinceNow - try self._play(in: timeLeft, repeatCount: repeatCount) + try self._play(in: timeLeft) } - func start(in duration: TimeInterval, repeatCount: Int) throws { - try self._play(in: duration, repeatCount: repeatCount) + func start(in duration: TimeInterval) throws { + try self._play(in: duration) } - fileprivate func _play(in duration: TimeInterval, repeatCount: Int) throws { + fileprivate func _play(in duration: TimeInterval) throws { Conductor.maestro.activateAudioSession() self._player.prepareToPlay() self._player.volume = 1.0 self._player.delegate = self - self._player.numberOfLoops = repeatCount +// self._player.numberOfLoops = repeatCount Logger.log("self._player.deviceCurrentTime = \(self._player.deviceCurrentTime)") let time: TimeInterval = self._player.deviceCurrentTime + duration diff --git a/LeCountdown/Sound/Sound.swift b/LeCountdown/Sound/Sound.swift index 6951b48..041515b 100644 --- a/LeCountdown/Sound/Sound.swift +++ b/LeCountdown/Sound/Sound.swift @@ -135,7 +135,7 @@ enum Sound: Int, CaseIterable, Identifiable, Localized { case trancosoBowl case natureOceanShore - static var `default`: Sound { .sbSEM_Synths_Loop4_Nothing_Like_You } + static var `default`: Sound { .ESM_Ambient_Game_Menu_Soft_Wood } var localizedString: String { switch self {