我正在使用 pause()
方法暂停视频。问题是音频继续播放...我还尝试从 Firefox 的 Javascript 控制台暂停它...没有发生。该视频采用 .ogg 格式,甚至无法在 Chrome 中播放(因为我认为它不受支持)。
我在 Amazon 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();
}
}
我之前已经发布过一个类似的问题...但是现在我正在使用其他浏览器,所以我想我必须创建一个新问题。
这是工作代码(感谢用户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();
}
}
}
最佳答案
我有一个类似的问题,已经被非常出色的编码员解决了。查看这篇文章。可能会有很大用处。 HTML5 Video Controls do not work
如果您使用的是 html 属性:
<video id="yourvideoID" poster="Pic.jpg" loop autoplay controls width="100%">
<source src="//example.website/InnovoThermometer.mp4" type="video/mp4">
</video>
删除自动播放。
然后使用 jquery 来使用自动播放:
$(document).ready(function() { $("#bigvid3").get(0).play(); });
至于来源有多个位置: html5 video playing twice (audio doubled) with JQuery .append()
和
关于javascript - 暂停视频不会停止 html5 视频标签中的音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11846617/