From 6a66e40489701da37d5ea521a8efb0c3a839a52b Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 22 May 2023 11:49:06 +0200 Subject: [PATCH] cleanup --- LeCountdown/AppDelegate.swift | 13 +------------ LeCountdown/Conductor.swift | 10 ++++++++++ LeCountdown/Sound/DelaySoundPlayer.swift | 5 ++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/LeCountdown/AppDelegate.swift b/LeCountdown/AppDelegate.swift index d46ff55..241f72e 100644 --- a/LeCountdown/AppDelegate.swift +++ b/LeCountdown/AppDelegate.swift @@ -27,7 +27,7 @@ class AppDelegate : NSObject, UIApplicationDelegate { UNUserNotificationCenter.current().delegate = self self._initSchemaIfNeeded() - self._activateAudioSession() + Conductor.maestro.activateAudioSession() Sound.computeSoundDurationsIfNecessary() @@ -66,17 +66,6 @@ class AppDelegate : NSObject, UIApplicationDelegate { } } - fileprivate func _activateAudioSession() { - Logger.log("_activateAudioSession") - do { - let audioSession: AVAudioSession = AVAudioSession.sharedInstance() - try audioSession.setCategory(.playback, options: .duckOthers) - try audioSession.setActive(true) - } catch { - Logger.error(error) - } - } - func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { if userActivity.interaction == nil { diff --git a/LeCountdown/Conductor.swift b/LeCountdown/Conductor.swift index f2c6563..7ac6f79 100644 --- a/LeCountdown/Conductor.swift +++ b/LeCountdown/Conductor.swift @@ -454,6 +454,16 @@ class Conductor: ObservableObject { self.soundPlayer.stop() } + func activateAudioSession() { + do { + let audioSession: AVAudioSession = AVAudioSession.sharedInstance() + try audioSession.setCategory(.playback, options: .duckOthers) + try audioSession.setActive(true) + } catch { + Logger.error(error) + } + } + // MARK: - Intent // fileprivate func _createTimerIntent(_ timer: AbstractTimer) { diff --git a/LeCountdown/Sound/DelaySoundPlayer.swift b/LeCountdown/Sound/DelaySoundPlayer.swift index 74923c5..2a7ad09 100644 --- a/LeCountdown/Sound/DelaySoundPlayer.swift +++ b/LeCountdown/Sound/DelaySoundPlayer.swift @@ -39,8 +39,8 @@ import AVFoundation fileprivate func _play(in duration: TimeInterval, repeatCount: Int) throws { - self._activateAudioSession() - + Conductor.maestro.activateAudioSession() + self._player.prepareToPlay() self._player.volume = 1.0 self._player.delegate = self @@ -73,7 +73,6 @@ import AVFoundation } fileprivate func _activateAudioSession() { - Logger.log("_activateAudioSession") do { let audioSession: AVAudioSession = AVAudioSession.sharedInstance() try audioSession.setCategory(.playback, options: .duckOthers)