Uma*_*mil 10 javascript firefox html5 google-chrome html5-video
我正在使用它的pause()方法暂停一个视频..问题是音频继续播放...我也尝试从Firefox中的Javascript控制台暂停...没有任何反应.该视频采用.ogg格式,甚至不在Chrome中播放(因为我认为它不受支持).我在亚马逊S3上托管了这个视频,它完美地流媒体.我正在动态创建元素,从JSON请求加载其信息.这是一些代码:
function showVideo() {
var video = videodata;
var videobox = $('#videobox').first();
var videoplayer = document.getElementById('videoplayer');
if (video.Enabled) {
if ((videoplayer != null && videoplayer.currentSrc != video.Location) || videoplayer == null) {
console.log('Creating video elem');
videobox.empty();
videobox.append('<video id="videoplayer" preload="auto" src="' +
video.Location + '" width="100%" height="100%" autoplay="autoplay" loop="loop" />');
videobox.show();
}
} else {
if (videoplayer != null) {
videoplayer.pause();
console.log('Pausing video...');
}
console.log('Deleting video elem');
videobox.hide();
videobox.empty();
}
}
Run Code Online (Sandbox Code Playgroud)
我之前已经发布了类似的问题...但现在我正在使用其他浏览器,所以我想我必须创建一个新问题.
这是工作代码(感谢用户heff!)
function showVideo() {
var video = videodata;
var videobox = $('#videobox').first();
var videoplayer = document.getElementById('videoplayer');
if (video.Enabled) {
if ((videoplayer.src != video.Location) || videoplayer.src == '') {
console.log('Playing video: ' + video.Location);
videoplayer.src = video.Location;
videoplayer.load();
videoplayer.play();
videobox.show();
}
} else {
if (videoplayer.src != '') {
console.log('Pausing video...');
videoplayer.pause();
videoplayer.src = '';
videobox.hide();
}
}
}
Run Code Online (Sandbox Code Playgroud)
嘿伙计我有一个类似的问题,这是由非常好的程序员解决的.看看这篇文章.它可能很有用.HTML5视频控件不起作用
如果您使用的是html属性:
<video id="yourvideoID" poster="Pic.jpg" loop autoplay controls width="100%">
<source src="//example.website/InnovoThermometer.mp4" type="video/mp4">
</video>Run Code Online (Sandbox Code Playgroud)
删除自动播放.
然后使用jquery来代替使用自动播放:
$(document).ready(function() { $("#bigvid3").get(0).play(); });Run Code Online (Sandbox Code Playgroud)
至于源有多个位置: html5视频播放两次(音频加倍)与JQuery .append()
和
我的猜测是 showVideo 被调用了两次,并创建了两个副本,其中一个即使在您调用另一个暂停后仍会继续播放。
在您的代码中,视频播放器 var 不会引用您稍后使用 append 创建的视频标签,它将指向之前具有该 ID 的任何内容,我假设在您清空框时将其删除,但可能会留在内存中(并继续播放声音)。
只是我最好的猜测,但无论哪种方式,最好使用视频元素的 API 来设置源和其他参数,而不是清空框并重建标签。
videoplayer.src = video.Location;
videoplayer.autoplay = true;
// etc.
Run Code Online (Sandbox Code Playgroud)
此外,100% 不是宽度/高度属性的有效值。您需要使用 CSS 使视频拉伸以填充一个区域。