视频.js播放器在释放并重新初始化后无法播放
Video.js Player Fails To Play After Dispose And Re-Initialize
我正在尝试在模式弹出窗口中使用视频.js播放器。我在模态加载时初始化播放器,并在模态关闭时处理它。它第一次工作正常,但是当我尝试再次打开弹出窗口并重新初始化播放器时,它不会在控制台中出现错误。
这是我的代码:
<a href="#openModal" id="open_modal_button">Open Modal</a>
<div id="openModal" class="modalDialog">
<div>
<a href="#close" title="Close" class="close" id="close_modal_button">X</a>
<div id='videoDiv'> </div>
</div>
</div>
<script type="text/javascript">
open_modal_button.addEventListener("click", function() {
var videoDiv = document.getElementById('videoDiv');
var video = createVideoElement('vid1');
addSource(video, "http://foo.mp4");
videoDiv.appendChild(video);
videojs('vid1', {}, function() {})
});
close_modal_button.addEventListener("click", function(e) {
var player = videojs('vid1');
player.dispose();
});
</script>
当我第二次启动模式时,我在浏览器控制台中收到以下错误消息:
Uncaught TypeError: window.videojs[componentClass] is not a function video.debug.js
Uncaught TypeError: Cannot read property 'className' of null video.debug.js
这是按照您正在做的事情进行的,并且没有错误。
<button id="add">Add player</button>
<button id="remove" disabled>Remove player</button>
<div id="videoDiv"></div>
<script type="text/javascript">
var open_modal_button = document.getElementById('add');
var close_modal_button = document.getElementById('remove');
open_modal_button.addEventListener("click", function() {
var videoDiv = document.getElementById('videoDiv');
var video = document.createElement('video');
var source = document.createElement('source');
video.id = 'vid1';
video.className = 'video-js vjs-default-skin';
video.setAttribute('controls', 'controls');
source.setAttribute('src', 'http://vjs.zencdn.net/v/oceans.mp4');
source.setAttribute('type', 'video/mp4');
video.appendChild(source);
videoDiv.appendChild(video);
videojs('vid1', {}, function() {});
close_modal_button.removeAttribute('disabled');
open_modal_button.setAttribute('disabled', true);
});
close_modal_button.addEventListener("click", function(e) {
var player = videojs('vid1');
player.dispose();
open_modal_button.removeAttribute('disabled');
close_modal_button.setAttribute('disabled', true);
});
</script>
示例:http://output.jsbin.com/ciqoji
相关文章:
- 使用javascript函数在页面初始化后加载jquery
- 未捕获错误:无法在初始化之前调用方法;
- 如何在剑道网格初始化后设置pageSizes
- React redux初始化功能,无论状态变化如何
- 为什么可以't Protractor在自动初始化的Angular网站上查找Angular
- 尝试初始化()Spine's控制器和故障
- Angular.js延迟控制器初始化
- 对插件初始化后动态加载的元素进行样式设置
- Angular JS控制器初始化错误
- 在XMLHttpRequest之后重新初始化jQuery
- ember-js组件初始化不同的函数
- Youtube JavaScript API不是't正在初始化
- 函数无法识别初始化的变量
- datepicker引导程序再次初始化
- jquery数据表在初始化时设置宽度
- 如何使用app和secret进行安全的解析初始化
- 魔术播放器初始化错误
- 在页面的 ajax 加载部分上初始化视频.js播放器
- 视频.js播放器在释放并重新初始化后无法播放
- Video.js:如何在初始化之前发现当前设备是否有本机播放