Attempting to learn how to play a sound on the watch. I created a test app (single view) on the phone and added the Watchkit extention to it. The only thing I put on the watch is a button. When the button is pressed, it will play the sound. I have the same sound on the phone part of the test app, and it plays the sound without issue, so I know the sound file is fine. The goal of this exercise it to have the sound played, without a "player" showing up. In any real apps that I make, the user will not be touching the device for the sound to be played. (From what I've read, the WKInterfaceMovie will play sounds, but it opens up a player, which is not what I'm looking for). Am I not using the correct feature to play sounds, is there something missing from the code below, or is this just a bug that hasn't been addressed yet?
class InterfaceController: WKInterfaceController {
var player: WKAudioFilePlayer!
@IBAction func buttonPlay() {
let filePath = NSBundle.mainBundle().pathForResource("SpeakMinder2", ofType: "wav")!
let fileUrl = NSURL.fileURLWithPath(filePath)
let asset = WKAudioFileAsset(URL: fileUrl)
let playerItem = WKAudioFilePlayerItem(asset: asset)
player = WKAudioFilePlayer(playerItem: playerItem) // This is where it crashes
player.play()
}
override func willActivate() {
/
super.willActivate()
}
override func didDeactivate() {
/
super.didDeactivate()
}
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
/
}
}
On the simulator for Watch, I get "Program ended with exit code 0", and on the actual device it just dies after hitting the button. The sound file was copied to the Watch Extension group.