diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-01-15 20:20:47 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-01-15 20:20:47 -0800 |
| commit | 7c9f6686044035c022a17551151cf1cbed0dc665 (patch) | |
| tree | d41403b6f64d3375fdea8cee48d9db91c3ce26e0 /Hotline/Utility | |
| parent | faae9cd1b47c6f22f3bcf4b1a24a4f7df41af9ed (diff) | |
Add classic sound effects. Fix read user access bits. Better no content/no access views. Add Server menu. Add keep alive ping to server every 3 minutes.
Diffstat (limited to 'Hotline/Utility')
| -rw-r--r-- | Hotline/Utility/SoundEffects.swift | 42 | ||||
| -rw-r--r-- | Hotline/Utility/Utilities.swift | 2 |
2 files changed, 42 insertions, 2 deletions
diff --git a/Hotline/Utility/SoundEffects.swift b/Hotline/Utility/SoundEffects.swift new file mode 100644 index 0000000..426bfa2 --- /dev/null +++ b/Hotline/Utility/SoundEffects.swift @@ -0,0 +1,42 @@ +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" +} + +@Observable +class SoundEffectPlayer: NSObject, AVAudioPlayerDelegate { + 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 + } + + do { + let soundEffect = try AVAudioPlayer(contentsOf: soundFileURL) + soundEffect.delegate = self + + self.activeSounds.append(soundEffect) + + soundEffect.volume = 0.75 + soundEffect.play() + } + catch {} + } + + func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) { + if let i = self.activeSounds.firstIndex(of: player) { + self.activeSounds.remove(at: i) + } + } +} diff --git a/Hotline/Utility/Utilities.swift b/Hotline/Utility/Utilities.swift deleted file mode 100644 index fbf2875..0000000 --- a/Hotline/Utility/Utilities.swift +++ /dev/null @@ -1,2 +0,0 @@ -import Foundation - |