javascript - play html5 video in reverse, on screen load -


i working on functionality on screen load, video should start playing reverse. (from last frame first frame). can on screen load or on button click.

at moment, i've achieved until (with , support stackoverflow) playing video - , playing in reverse after duration of time. here's code used-

<!doctype html> <html> <head> <style> video{     height: 200px; } </style> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(function() {  var video = document.getelementbyid('video'); var intervalrewind; $(video).on('play',function(){     //video.playbackrate = 1.0;     clearinterval(intervalrewind); }); $(video).on('pause',function(){     video.playbackrate = 1.0;     clearinterval(intervalrewind); }); $("#speed").click(function() { // button function 3x fast speed forward     video.playbackrate = 8.0; }); $("#negative").click(function() { // button function rewind    intervalrewind = setinterval(function(){        video.playbackrate = 1.0;        if(video.currenttime == 0){            clearinterval(intervalrewind);            video.pause();        }        else{            video.currenttime += -.1;        }                 },30); }); }); </script>  </head> <body>    <video id="video" controls>     <source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4">     <source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.webm" type="video/webm">     <source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.ogv" type="video/ogg"> </video>         <button id="speed">fast forward</button>         <button id="negative">rewind</button> </body> </html> 

now, know if there chance play video in reverse directly i.e. without progressing duration in forward direction, video should start playing in reverse.

you need wait until video loaded, can it's length video.duration , can set video current time value (jump end of video);

then can start playing video last frame first using negative function.

  video.addeventlistener('loadeddata', function() {      video.currenttime = video.duration;      $('#negative').click();   }, false); 

there nice fiddle video playbacks @ http://jsfiddle.net/ukmv2/5/ found play video in reverse using html5 video element

following example super modified version of your's achieves "reverse" playback upon page & video loaded event.

<!doctype html> <html> <head> <style> video{     height: 200px; } </style> <script src="http://code.jquery.com/jquery-1.9.1.js"></script>  </head> <body>    <video id="video" controls>       <source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4">       <source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.webm" type="video/webm">       <source src="http://www.quirksmode.org/html5/videos/big_buck_bunny.ogv" type="video/ogg">   </video>   <button id="speed">fast forward</button>   <button id="negative">rewind</button>     <script>   $(function() {    var video = document.getelementbyid('video');   var intervalrewind;     $(video).on('play',function(){       //video.playbackrate = 1.0;       clearinterval(intervalrewind);   });   $(video).on('pause',function(){       video.playbackrate = 1.0;       clearinterval(intervalrewind);   });   $("#speed").click(function() { // button function 3x fast speed forward       video.playbackrate = 8.0;   });   $("#negative").click(function() { // button function rewind      intervalrewind = setinterval(function(){          video.playbackrate = 1.0;          if(video.currenttime == 0){              clearinterval(intervalrewind);              video.pause();          }          else{              video.currenttime += -.1;          }                   },30);   });    video.addeventlistener('loadeddata', function() {      video.currenttime = video.duration;      $('#negative').click();   }, false);      });   </script>  </body> </html> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -