From 45829daa856b376b1ab04d415917110b71b1dec5 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Wed, 5 Feb 2025 22:27:17 +0100 Subject: Apply formatting --- Hotline/Utility/SoundEffects.swift | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'Hotline/Utility/SoundEffects.swift') diff --git a/Hotline/Utility/SoundEffects.swift b/Hotline/Utility/SoundEffects.swift index 93f8b9a..74314e4 100644 --- a/Hotline/Utility/SoundEffects.swift +++ b/Hotline/Utility/SoundEffects.swift @@ -1,5 +1,5 @@ -import Foundation import AVFAudio +import Foundation enum SoundEffects: String { case loggedIn = "logged-in" @@ -15,28 +15,30 @@ enum SoundEffects: String { @Observable class SoundEffectPlayer: NSObject, AVAudioPlayerDelegate { static let shared = SoundEffectPlayer() - + private var activeSounds: [AVAudioPlayer] = [] - + func playSoundEffect(_ name: SoundEffects) { // Load a local sound file - guard let soundFileURL = Bundle.main.url( - forResource: name.rawValue, - withExtension: "aiff" - ) else { + guard + let soundFileURL = Bundle.main.url( + forResource: name.rawValue, + withExtension: "aiff" + ) + else { return } - + DispatchQueue.main.async { [weak self] in guard let self = self else { return } - + if let soundEffect = try? AVAudioPlayer(contentsOf: soundFileURL) { soundEffect.delegate = self soundEffect.volume = 0.75 soundEffect.play() - + self.activeSounds.append(soundEffect) } } -- cgit