I'm attempting to make a basic WatchOS app that plays a short audio clip when the user taps on a button.
I have already encoded the test audio file as 32 kbps / 16-bit stereo AAC. I found support info saying that since WatchOS 3, this meager sample rate is max allowed.
Prior to encoding the audio file down, I would get an Xcode error with my code below. But after transcoding the file to ~32kbps I no longer get the error....
BUT, even though it builds fine onto my Series 3 Watch running WatchOS 5, I cannot get any audio sound to come out. Yes I checked to ensure it's not on silent mode.
SO, my question is, what am I doing wrong if I just want the Apple Watch to play an audio file out of it's built in speaker (no bluetooth headphones). Please help!
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
var soundPlayer: WKAudioFilePlayer!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
let mainBundle = Bundle.main
if let url = mainBundle.url(forResource: "testaudio", withExtension: "aac"){
let asset = WKAudioFileAsset(url: url)
let playerItem = WKAudioFilePlayerItem(asset: asset)
soundPlayer = WKAudioFileQueuePlayer(playerItem: playerItem)
if soundPlayer.status == .readyToPlay {
soundPlayer.play()
}
}
// let filePath = Bundle.main.path(forResource: "se_tap", ofType: "m4a")
// let fileUrl = URL(fileURLWithPath: filePath)
// let asset = WKAudioFileAsset(url: fileUrl)
// let playerItem = WKAudioFilePlayerItem(asset: asset)
// player = WKAudioFilePlayer(playerItem: playerItem)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
@IBAction func buttonTapVoz() {
soundPlayer.play()
}
}