gecko-dev/mobile/xul/chrome/content/fullscreen-video.xhtml

199 строки
5.1 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<!--
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<html xmlns="http://www.w3.org/1999/xhtml" accelerated="11">
<head>
<style type="text/css"><![CDATA[
html,
body,
video {
height: 100%;
}
body {
margin: 0;
background: black;
overflow: -moz-hidden-unscrollable;
}
body.userIdle {
cursor: none;
}
video {
width: 100%;
max-height: 100%;
}
body.loadingdata > video,
body.loadingdata > #close,
body.userIdle > #close {
visibility: hidden;
}
#close {
position: absolute;
top: 0;
right: 0;
width: 32px;
height: 32px;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAB3RJTUUH2AUXDg4nBoBhWwAAAAlwSFlzAAAPYAAAD2ABenhFjQAAAARnQU1BAACxjwv8YQUAAAEYSURBVHjaY2BgYOAAYtXk5OQAEA3EnAzkAUYg5gFidahZikDMBpJQvXHjxqP/QHDhwoUHmpqarlCFpBou4OzsHH7nzp3XILOOHDlyHigmz1BQUBD5Hwlcu3bthYaGhhsJloANd3Jyinz8+PEnmDl//vz5Z2RkZAFSoAGzlQxLsBoOAidPnrwJlFMAKeIBeQ1dARGW4DQcpFdLS8sZFp94FeKwhBg93KRq4CFDLcmu4gViQXIMJ8oSJSWlIBsbmyRyDSdoCTCfvH/w4MFXCpM1fkuoYTiyJYLW1tbJ9+/f/4Zu+MWLF98pKysHQOMFJ2Aix2ZqAJoGEU0jmabJlKYZjaZFBc0LO5oX17StcOhRZdK20megcbMFAI0gGfYvgPhiAAAAAElFTkSuQmCC) center center no-repeat;
}
]]></style>
<script type="application/javascript;version=1.8"><![CDATA[
Components.utils.import("resource:///modules/video.jsm");
var contentVideo = Video.fullScreenSourceElement;
Video.fullScreenSourceElement = null;
var video;
function init() {
video = document.querySelector("video");
video.addEventListener("loadeddata", function () {
video.removeEventListener("loadeddata", arguments.callee, false);
video.volume = contentVideo.volume;
video.muted = contentVideo.muted;
video.poster = contentVideo.poster;
if (contentVideo.currentTime && !contentVideo.ended) {
video.addEventListener("seeked", function () {
video.removeEventListener("seeked", arguments.callee, false);
playbackStarts();
}, false);
video.currentTime = contentVideo.currentTime;
} else {
playbackStarts();
}
showUI();
resetIdleTimer();
sendStartEvent(video);
}, false);
// Automatically close this window when the playback ended, unless the user
// interacted with it.
video.addEventListener("ended", close, false);
window.addEventListener("click", cancelAutoClose, false);
window.addEventListener("keypress", cancelAutoClose, false);
video.addEventListener("seeked", hideUI, false);
video.addEventListener("seeking", showUI, false);
video.addEventListener("pause", pause, false);
video.addEventListener("play", play, false);
video.addEventListener("ended", showUI, false);
window.addEventListener("click", function () {
toggleUI();
resetIdleTimer();
}, false);
video.mozLoadFrom(contentVideo);
}
function sendStartEvent(aElt) {
let event = document.createEvent("Event");
event.initEvent("StartVideo", true, true);
aElt.dispatchEvent(event);
}
window.addEventListener("unload", function () {
if (video.currentSrc) {
contentVideo.currentTime = video.currentTime;
contentVideo.volume = video.volume;
contentVideo.muted = video.muted;
if (!video.paused && !video.ended) {
video.pause();
contentVideo.play();
}
}
}, false);
window.addEventListener("keypress", function (event) {
if (event.keyCode == event.DOM_VK_ESCAPE) {
close();
return;
}
resetIdleTimer();
if (!video.controls &&
String.fromCharCode(event.charCode) == " ")
video.pause();
}, false);
function playbackStarts() {
// Loading the data from the content video may take a second or two. We hide
// the video during that period.
document.body.classList.remove("loadingdata");
video.focus();
}
function close() {
let event = document.createEvent("Events");
event.initEvent("CloseVideo", true, true);
window.dispatchEvent(event);
}
function cancelAutoClose() {
video.removeEventListener("ended", close, false);
window.removeEventListener("click", cancelAutoClose, false);
window.removeEventListener("keypress", cancelAutoClose, false);
}
function play() {
let event = document.createEvent("Events");
event.initEvent("PlayVideo", true, true);
window.dispatchEvent(event);
}
function pause() {
showUI();
let event = document.createEvent("Events");
event.initEvent("PauseVideo", true, true);
window.dispatchEvent(event);
}
var idleTimer;
function resetIdleTimer() {
if (idleTimer) {
clearTimeout(idleTimer);
idleTimer = 0;
}
idleTimer = setTimeout(function () {
idleTimer = 0;
hideUI();
}, 5000);
}
var showingUI = false;
function toggleUI() {
if (showingUI)
hideUI();
else
showUI();
}
function showUI() {
showingUI = true;
document.body.classList.remove("userIdle");
}
function hideUI() {
showingUI = false;
document.body.classList.add("userIdle");
}
]]></script>
</head>
<body class="loadingdata" onload="init();">
<span id="close"/>
<video controls="true"/>
</body>
</html>