Skip to content

Instantly share code, notes, and snippets.

@barata0
Created December 6, 2017 02:19
Show Gist options
  • Save barata0/f1811cbe6fe2f1e01215d354fd819e97 to your computer and use it in GitHub Desktop.
Save barata0/f1811cbe6fe2f1e01215d354fd819e97 to your computer and use it in GitHub Desktop.
html5 video with positive and negative playbackrates (jog, shuttle and seeking)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<title>HTML5 backward playback Video</title>
</head>
<body>
<div>
<video id='video'
width="360"
height="240"
controls
preload="auto">
<source id='mp4'
src="VIDEOFILE.mov"
type='video/mp4'>
<p>Your user agent does not support the HTML5 Video element.</p>
</video>
<div id='buttons'>
<button onclick="rev();">rev</button>
<button onclick="ff();">ff</button>
<button onclick="stop();">stop</button>
</div>
<table>
<caption>Media Events</caption>
<tbody id='events'>
</tbody>
</table>
<table>
<caption>Media Properties</caption>
<tbody id='properties'>
</tbody>
</table>
<table id='canPlayType'>
<caption>canPlayType</caption>
<tbody id='m_video'>
</tbody>
</table>
<table id='tracks'>
<caption>Tracks</caption>
<tbody>
<tr>
<th>Audio</th>
<th>Video</th>
<th>Text</th>
</tr>
<tr>
<td id='m_audiotracks' class='false'>?</td>
<td id='m_videotracks' class='false'>?</td>
<td id='m_texttracks' class='false'>?</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function getVideo() {
return document.getElementById('video');
}
var jog = 0;
function rev() {
console.log('rev')
jog--
tryJog();
}
function ff() {
console.log('ff')
jog++
tryJog();
}
function stop() {
console.log('stop')
jog = 0;
getVideo().pause();
tryJog();
}
function tryJog() {
var j = jog
console.log('jog=' + jog);
if (j != 0) {
// from 1 to 4 html playback is adjusted
if (j >= 1 && j <= 4) {
console.log('playbackRate=' + j);
getVideo().playbackRate = j;
getVideo().play();
}
// lower than zero or higher than 4
// implements a jump and wait seek
if (j < 0 || j > 4) {
var interv = 0; // playing interval before jog
var s = 0; // the increase seek position
if (j > 0) {
s = j / 2;
interv = 50;
} else {
s = j / 2;
interv = 50;
}
console.log('jumping=' + j);
getVideo().playbackRate = 1;
getVideo().play(); // better user xp
setTimeout(function () {
getVideo().currentTime += (s); // after jumping oncanplay will be fired
}, interv);
}
}
}
getVideo().oncanplay = function() {
// every time the video is repositioned try jog
tryJog();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment