From 7c9f6686044035c022a17551151cf1cbed0dc665 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Mon, 15 Jan 2024 20:20:47 -0800 Subject: 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. --- Hotline/Utility/SoundEffects.swift | 42 ++++++++++++++++++++++++++++++++++++++ Hotline/Utility/Utilities.swift | 2 -- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Hotline/Utility/SoundEffects.swift delete mode 100644 Hotline/Utility/Utilities.swift (limited to 'Hotline/Utility') 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 - -- cgit