mirror of
https://github.com/Erreur32/html5demos.git
synced 2024-10-01 14:41:34 +02:00
77 lines
2.1 KiB
HTML
77 lines
2.1 KiB
HTML
<title>Video</title>
|
|
<article>
|
|
<video>
|
|
<source src="assets/dizzy.webm" />
|
|
<source src="assets/dizzy.mp4" />
|
|
<source src="assets/dizzy.ogv" />
|
|
</video>
|
|
<p id="controls">
|
|
<input type="button" id="play" value="play">
|
|
<span id="position">00:00</span> / <span id="duration">loading...</span>
|
|
</p>
|
|
<p>Video loaded: <span id="using">loading...</span></p>
|
|
<p>Note that (at time of writing) <a href="http://webkit.org/" title="The WebKit Open Source Project">Webkit nightly</a> supports full screen mode, which will add a button above.</p>
|
|
</article>
|
|
<script>
|
|
var video = document.querySelector('video'),
|
|
togglePlay = document.querySelector('#play'),
|
|
position = document.querySelector('#position'),
|
|
using = document.querySelector('#using'),
|
|
ready = false,
|
|
controls = document.querySelector('#controls'),
|
|
fullscreen = null;
|
|
|
|
addEvent(togglePlay, 'click', function () {
|
|
if (ready) {
|
|
video.playbackRate = 0.5;
|
|
if (video.paused) {
|
|
if (video.ended) video.currentTime = 0;
|
|
video.play();
|
|
this.value = "pause";
|
|
} else {
|
|
video.pause();
|
|
this.value = "play";
|
|
}
|
|
}
|
|
});
|
|
|
|
addEvent(video, 'timeupdate', function () {
|
|
position.innerHTML = asTime(this.currentTime);
|
|
});
|
|
|
|
addEvent(video, 'ended', function () {
|
|
togglePlay.value = "play";
|
|
});
|
|
|
|
addEvent(video, 'canplay', function () {
|
|
video.muted = true;
|
|
ready = true;
|
|
document.querySelector('#duration').innerHTML = asTime(this.duration);
|
|
using.innerHTML = this.currentSrc;
|
|
// note: .webkitSupportsFullscreen is false while the video is loading, so we bind in to the canplay event
|
|
if (video.webkitSupportsFullscreen) {
|
|
fullscreen = document.createElement('input');
|
|
fullscreen.setAttribute('type', 'button');
|
|
fullscreen.setAttribute('value', 'fullscreen');
|
|
controls.insertBefore(fullscreen, controls.firstChild);
|
|
addEvent(fullscreen, 'click', function () {
|
|
video.webkitEnterFullScreen();
|
|
});
|
|
}
|
|
|
|
});
|
|
|
|
function asTime(t) {
|
|
t = Math.round(t);
|
|
var s = t % 60;
|
|
var m = Math.round(t / 60);
|
|
|
|
return two(m) + ':' + two(s);
|
|
}
|
|
|
|
function two(s) {
|
|
s += "";
|
|
if (s.length < 2) s = "0" + s;
|
|
return s;
|
|
}
|
|
</script> |