So wondering if anyone has gotten the watch to play any sounds. I've been looking for good sample code to update my old application which relied on the phone to produce the sounds. I found different examples people have been using and nothing seems to work. Currently my code looks as follows:
import WatchKit
import Foundation
var player: WKAudioFilePlayer!
class InterfaceController: WKInterfaceController {
@IBOutlet var TestButton: WKInterfaceButton!
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// 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 testPressed() {
print("test pressed")
let filePath = NSBundle.mainBundle().pathForResource("flute", ofType: "mp3")!
let fileUrl = NSURL.fileURLWithPath(filePath)
let asset = WKAudioFileAsset(URL: fileUrl)
let playerItem = WKAudioFilePlayerItem(asset: asset)
player = WKAudioFilePlayer(playerItem: playerItem)
player.play()
}
It loads on the simulator ok, but shows a bluetooth device is needed error when the button is pressed. On the watch itself, it doesn't seem to do anything. I'm working on updating my old app and have lots of sounds to use so need to figure out a good system.