Search code examples
javascriptjqueryhtmlhtml5-videopopcornjs

How to lock controls on <video> in HTML5 till a given event happens?


I want to pause the video being played at a particular instant till a question that pops up has been answered. The user should not be able to go ahead and forward the video till a particular question that has just poppped up has been answered.

So I can pause the video using JS at that particular instant. How can I ensure the video's controls are unlocked or the video plays again only after answering the question that pops up?


Solution

  • look at this demo http://jsfiddle.net/dgLds/58/

    var video = document.getElementById("myvideo");
    
    
    function toggleControls() {
        document.getElementById('myvideo').pause();
      if (video.hasAttribute("controls")) {
         video.removeAttribute("controls")   
      } else {
         video.setAttribute("controls","controls")   
      }
    }
    
    
    <video id="myvideo">
        <source src="http://www.w3schools.com/html5/movie.mp4" />
    </video>
    
    <p onclick="toggleControls();">Toggle</p>
    

    instead of on click you can call the function when ever you want

    Here is a opera article on everything you wish to know about html5 video http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/

    Specifically look at How to keep things synchronized section

    EDIT: I you want to disable right-click options. Just go ahead and disable right click on that tag/id

    Here is a jquery code

     $('video').bind('contextmenu', function() 
        {
            alert('no right click.');
            return false;
        });