Files
WerkoutIOS/iphone/Werkout_ios/AudioEngine.swift

67 lines
2.1 KiB
Swift

//
// AudioEngine.swift
// Werkout_ios
//
// Created by Trey Tartt on 6/21/24.
//
import AVKit
class AudioEngine {
// var audioPlayer: AVAudioPlayer?
// var avPlayer: AVPlayer?
static func playRemoteAudio(fromURL url: URL) {
#if os(iOS)
let playerItem = AVPlayerItem(url: url)
do {
try AVAudioSession.sharedInstance().setCategory(.playback,
mode: .default,
options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
let avPlayer = AVPlayer(playerItem: playerItem)
avPlayer.play()
} catch {
print("ERROR")
}
#endif
}
static func playBeep() {
#if os(iOS)
if let path = Bundle.main.path(forResource: "short_beep", ofType: "m4a") {
do {
try AVAudioSession.sharedInstance().setCategory(.playback,
mode: .default,
options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
let audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer.play()
} catch {
print("ERROR")
}
}
#endif
}
static func playFinished() {
#if os(iOS)
if let path = Bundle.main.path(forResource: "long_beep", ofType: "m4a") {
do {
try AVAudioSession.sharedInstance().setCategory(.playback,
mode: .default,
options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setActive(true)
let audioPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: path))
audioPlayer.play()
} catch {
print("ERROR")
}
}
#endif
}
}