Forum Archive

Video Playing

robertiii

A while back I enquirer on here about how to get a video to play. I was given a link and used it. I have figured out how to get the video to show, but I need a way to have buttons play, pause, go to the beginning or go to the end.

def showVideo(video, viewToShowOn):
    i=AVPlayerItem.playerItemWithAsset_(video)
    p=AVPlayer.playerWithPlayerItem_(i)
    name = str(i)
    videolayer=AVPlayerLayer.playerLayerWithPlayer_(p)
    V=ObjCInstance(viewToShowOn)
    videolayer.frame=V.bounds()
    V.layer().addSublayer_(videolayer)

This is the function I use to set the video. How would I go about calling that layer to use the play? Here is the link I was given to add the video.

https://gist.github.com/3e708b73a04e5fc2e04569d9556198e3https://gist.github.com/3e708b73a

I need to set up a button to play. But I don’t know how to call the player to have it play from outside the showVideo() function

JonB

If you look back at the original, you will notice the p.play().

It is often helpful to go into the console, and let autocomplete should you what methods exist -- for instance typing p. shows that there is a play(), pause(), and other methods.

robertiii

Ok. But how would I set p.play outside that def

JonB

you just need to store a reference to your player. For instance it could be an instance variable of your root view:

v.player=p

later:

v.player.play()

Or, in your button action:
sender.superview.player.play()

robertiii

Thank you sooooo much!!!!