aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Utility/SoundEffects.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-02-05 22:27:17 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2025-02-05 22:27:17 +0100
commit45829daa856b376b1ab04d415917110b71b1dec5 (patch)
tree8e52daed6897b6f489d455736fe256cb9bd90fef /Hotline/Utility/SoundEffects.swift
parent5c3ea897d062a47bc8cd6255fb8c36bad2f0733f (diff)
Apply formatting
Diffstat (limited to 'Hotline/Utility/SoundEffects.swift')
-rw-r--r--Hotline/Utility/SoundEffects.swift22
1 files changed, 12 insertions, 10 deletions
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)
}
}