Dimitri T Dimitri T - 2 months ago 9x
iOS Question

how to start movie on phone AV controller from watch button in swift 2.2?

On my watch I have 2 buttons, IBAction playMovie and stopMovie. I have the AVViewController in my iPhone, and movie.mp4 in my phone Images assets. How can I trigger to start and end the movie on AVViewController on the phone target, from the watch button?

I tried player.play() on my watch controller, and this code on the iPhone view controller, but it brings error 'use of unresolved identifier' player on the watch code. Or i call function playmovie() it brings red flag error 'expected declaration'.

iPhone code:
func playmovie(){

let videoURL = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("video1bunny", ofType:"mp4")!)
let player = AVPlayer(URL: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
presentViewController(playerViewController, animated: true) { () -> Void in



You can't segue from a watchOS control to an iOS scene, or have a watchOS action invoke an iOS method or present an iOS view controller.

Your watch code runs on the watch, your iOS code runs on the phone. One app wouldn't be able to call or execute another app's code.

Using Watch Connectivity

You can accomplish what you want by using the WatchConnectivity framework, which allows you to transfer data between your watch app and its paired iOS app.

For example, the watch app could use WCSession sendMessage to send a specific ("playMovie" or "stopMovie") message to the iOS app.

The iOS app WCSessionDelegate didReceiveMessage would handle the specific message received from the watch, and the phone could then locally start or stop playing the movie.

Further information

This SO answer introduces how to setup and start using Watch Connectivity.

For more specifics, refer to this Introducing Watch Connectivity WWDC video, and the Developer Library WCSession Class Reference and WCSessionDelegate Protocol Reference documentation.