misc watch stuff including taps, sounds, maybe working
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user