Fixes repeating sound

splits
Laurent 2 years ago
parent 83a74df852
commit 977c44eb05
  1. 5
      LeCountdown/Conductor.swift
  2. 12
      LeCountdown/Sound/DelaySoundPlayer.swift
  3. 2
      LeCountdown/Sound/Sound.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 {

@ -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

@ -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 {

Loading…
Cancel
Save