【发布时间】:2015-07-15 19:18:29
【问题描述】:
我正在尝试创建一个带有视频精灵的小项目,以this JSFiddle for audio sprites 为模型。
播放按预期工作:点击相关按钮播放视频的相关部分。
但是,现在,我想加入一些东西,当按下按钮或按下某个键时,可以使视频以全屏(或全窗口)播放。演示 here, for example 展示了一种方法,如果您在播放视频时单击 Enter,它将进入全屏模式。
我对 JavaScript 没有特别的经验,因此该解决方案很可能让我对如何集成 Mozilla 文章中显示的方法直言不讳,但我被难住了。
这是我现在所拥有的,它可以按预期创建视频精灵:
var videoSprite = document.getElementById('bbb');
// sprite data
var spriteData = {
full: {
start: 0,
length: 595
},
tentotwenty: {
start: 10,
length: 10
},
tentothirty: {
start: 10,
length: 20
},
fiftytoonefifty: {
start: 50,
length: 200
}
};
// current sprite being played
var currentSprite = {};
// time update handler to ensure we stop when a sprite is complete
var onTimeUpdate = function() {
if (this.currentTime >= currentSprite.start + currentSprite.length) {
this.pause();
}
};
videoSprite.addEventListener('timeupdate', onTimeUpdate, false);
// in mobile Safari, the first time this is called will load the audio. Ideally, we'd load the audio file completely before doing this.
var playSprite = function(id) {
if (spriteData[id] && spriteData[id].length) {
currentSprite = spriteData[id];
videoSprite.currentTime = currentSprite.start;
videoSprite.play();
}
};
<video id="bbb">
<source src="https://ia700408.us.archive.org/26/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4" type="video/mp4" />
</video>
<br />
<br />
<ul>
<li>
<button onclick="playSprite('full');">Play full video</button>
</li>
<li>
<button onclick="playSprite('tentotwenty');">Play from 10 to 20 seconds</button>
</li>
<li>
<button onclick="playSprite('tentothirty');">Play from 10 to thirty seconds</button>
</li>
<li>
<button onclick="playSprite('fiftytoonefifty');">Play from 50 to 200 seconds</button>
</li>
</ul>
任何关于如何将其扩展为全屏或全窗口的提示将不胜感激!
【问题讨论】:
标签: javascript html video