misc watch stuff including taps, sounds, maybe working

This commit is contained in:
Trey t
2024-06-21 14:34:23 -05:00
parent 7ce996e451
commit cee84d7776
9 changed files with 61 additions and 36 deletions

View File

@@ -6,12 +6,16 @@
//
import AVKit
import AVFoundation
class AudioEngine {
// var audioPlayer: AVAudioPlayer?
// var avPlayer: AVPlayer?
static let shared = AudioEngine()
private init() { }
static func playRemoteAudio(fromURL url: URL) {
var audioPlayer: AVAudioPlayer?
var avPlayer: AVPlayer?
func playRemoteAudio(fromURL url: URL) {
#if os(iOS)
let playerItem = AVPlayerItem(url: url)
do {
@@ -20,15 +24,15 @@ class AudioEngine {
options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
let avPlayer = AVPlayer(playerItem: playerItem)
avPlayer.play()
avPlayer = AVPlayer(playerItem: playerItem)
avPlayer?.play()
} catch {
print("ERROR")
}
#endif
}
static func playBeep() {
func playBeep() {
#if os(iOS)
if let path = Bundle.main.path(forResource: "short_beep", ofType: "m4a") {
do {
@@ -37,8 +41,8 @@ class AudioEngine {
options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
let audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer.play()
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer?.play()
} catch {
print("ERROR")
}
@@ -46,7 +50,7 @@ class AudioEngine {
#endif
}
static func playFinished() {
func playFinished() {
#if os(iOS)
if let path = Bundle.main.path(forResource: "long_beep", ofType: "m4a") {
do {
@@ -55,8 +59,8 @@ class AudioEngine {
options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
let audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer.play()
audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer?.play()
} catch {
print("ERROR")
}