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


on watch have 2 buttons, ibaction playmovie , stopmovie. have avviewcontroller in iphone, , movie.mp4 in phone images assets. how can trigger start , end movie on avviewcontroller on phone target, watch button?

i tried player.play() on watch controller, , code on iphone view controller, brings error 'use of unresolved identifier' player on watch code. or call function playmovie() 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         player.play()  } 

you can't segue watchos control ios scene, or have watchos action invoke ios method or present ios view controller.

your watch code runs on watch, ios code runs on phone. 1 app wouldn't able call or execute app's code.

using watch connectivity

you can accomplish want using watchconnectivity framework, allows transfer data between watch app , paired ios app.

for example, watch app use wcsession sendmessage send specific ("playmovie" or "stopmovie") message ios app.

the ios app wcsessiondelegate didreceivemessage handle specific message received watch, , phone locally start or stop playing movie.

further information

this answer introduces how setup , start using watch connectivity.

for more specifics, refer introducing watch connectivity wwdc video, , developer library wcsession class reference , wcsessiondelegate protocol reference documentation.


Comments