How do I trigger a segued iOS AVPlayer
to start and stop playing (using Swift 2.2)?
My Watch Connectivity is sending "start" and "stop" message commands. How do I code the functions here to respond and react with the player?
The Watch connectivity messages are working correctly to play audio with AudioPlayer in a different view controller. I'm now trying to adapt this to control a video.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as!
AVPlayerViewController
let url = NSURL(string: self.specimen.filmMovieLink)
destination.player = AVPlayer(URL: url!)
}
// WATCH CONNECTIVITY MESSAGE TO TRIGGER START AND STOP VIDEO
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) {
var replyValues = Dictionary<String, AnyObject>()
switch message["command"] as! String {
case "start" :
//play video - correct here
player.Play()
replyValues["status"] = "Playing"
case "stop" :
//stop video - correct here
player.stopPlay()
replyValues["status"] = "Stopped"
case "volume" :
let level = message["level"] as! Float
//player.adjustVolume(level)
replyValues["status"] = "Vol = \(level)"
default:
break
}
replyHandler(replyValues)
}
}
I am getting the error messages "use of unresolved identifier 'player' on the lines player.Play() and player.StopPlay(). I have tried replacing 'player' with 'AVPlayer', 'destination', and 'AVPlayerViewController' but it doesn't fix it.