omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Video Playing

    Pythonista
    2
    5
    1962
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • robertiii
      robertiii last edited by

      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

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • robertiii
          robertiii last edited by

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

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            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()

            1 Reply Last reply Reply Quote 0
            • robertiii
              robertiii last edited by

              Thank you sooooo much!!!!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors