ios - How does one add a callback or get a notification when play is tapped? -
i have added video view using following code:
let url = nsbundle.mainbundle().urlforresource("etude", withextension:"mp4") player = avplayer(url: url!) let playerviewcontroller = avplayerviewcontroller() playerviewcontroller.player = player playerviewcontroller.view.frame = cgrect(x: xpos, y: ypos, width: videowidth, height: videoheight) self.view.addsubview(playerviewcontroller.view) self.addchildviewcontroller(playerviewcontroller)
i have other events trigger when user taps play button on player. there way set call when happens or perhaps add observer detect it?
yes can register key-value-observing playerviewcontroller.player.rate.
looks
self.player.addobserver(observer:self,keypath:"rate",options:0,context:nil)
then implement
func observevalueforkeypath(_ keypath: string?, ofobject object: anyobject?, change change: [string : anyobject]?, context context: unsafemutablepointer<void>) { if(self.player.rate==1){ print("playing") }else if(self.player.rate == 0){ print("stopped") } }
Comments
Post a Comment