aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Utility/SoundEffects.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-11-07 12:44:55 -0800
committerDustin Mierau <dustin@mierau.me>2025-11-07 12:44:55 -0800
commita55318fa8d643160900bec3e6b14e7404c63497a (patch)
treeab6a9eca9a368b35e1490becc70f94ebde6ac271 /Hotline/Utility/SoundEffects.swift
parent786a387d58fc66ae20716a9dee46b74dff8e6894 (diff)
Organize Library folder a bit. Update Tracker add/edit sheet design.
Diffstat (limited to 'Hotline/Utility/SoundEffects.swift')
-rw-r--r--Hotline/Utility/SoundEffects.swift50
1 files changed, 0 insertions, 50 deletions
diff --git a/Hotline/Utility/SoundEffects.swift b/Hotline/Utility/SoundEffects.swift
deleted file mode 100644
index 93f8b9a..0000000
--- a/Hotline/Utility/SoundEffects.swift
+++ /dev/null
@@ -1,50 +0,0 @@
-import Foundation
-import AVFAudio
-
-enum SoundEffects: String {
- case loggedIn = "logged-in"
- case chatMessage = "chat-message"
- case transferComplete = "transfer-complete"
- case userLogin = "user-login"
- case userLogout = "user-logout"
- case newNews = "new-news"
- case serverMessage = "server-message"
- case error = "error"
-}
-
-@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 {
- 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)
- }
- }
- }
-
- func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
- if let i = self.activeSounds.firstIndex(of: player) {
- self.activeSounds.remove(at: i)
- }
- }
-}