Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Video.js正在更改源,但不显示新源_Javascript_Video.js - Fatal编程技术网

Javascript Video.js正在更改源,但不显示新源

Javascript Video.js正在更改源,但不显示新源,javascript,video.js,Javascript,Video.js,对不起,我对这个话题缺乏了解 我有一个脚本,可以更改视频播放器的源代码。它就是这样做的。唯一的问题是Video.js播放器播放分配给它的第一个源 document.getElementById("vid-player_html5_api").innerHTML = ""; document.getElementById("vid-player_html5_api").innerHTML = "<source src='

对不起,我对这个话题缺乏了解

我有一个脚本,可以更改视频播放器的源代码。它就是这样做的。唯一的问题是Video.js播放器播放分配给它的第一个源

document.getElementById("vid-player_html5_api").innerHTML = "";

document.getElementById("vid-player_html5_api").innerHTML = "<source src='" + link + "' type='video/mp4'>";
document.getElementById("vid-player_html5_api").muted = false;
document.getElementById(“vid-player_html5_api”).innerHTML=“”;
document.getElementById(“vid-player_html5_api”).innerHTML=“”;
document.getElementById(“vid-player_html5_api”).mute=false;
因此,如果有两个按钮,您单击按钮1,它将更改播放器的来源并显示正确的视频。然后,假设您单击按钮2,它将更改播放机的来源,但它仍将显示与按钮1相同的视频

事实证明,它改变了源代码,我检查了Chrome开发工具,它确实改变了源代码


如何修复此问题?加载新视频后,您需要再次调用video.js:

var current_vid = document.getElementById("vid-player_html5_api")
var next_vid = document.createElement('video');

next_vid.innerHTML = '<source src="' + link + '" type="video/mp4">';
next_vid.muted = false;

current_vid.parentNode.replaceChild( next_vid, current_vid );

videojs(current_vid, {}, function(){
  // do something when video.js is ready
});
var current\u vid=document.getElementById(“vid-player\u html5\u api”)
var next_vid=document.createElement('video');
next_vid.innerHTML='';
next_vid.muted=false;
当前\u vid.parentNode.replaceChild(下一个\u vid,当前\u vid);
videojs(当前视频,{},函数(){
//当video.js准备就绪时执行一些操作
});

加载新视频后,您需要再次调用video.js:

var current_vid = document.getElementById("vid-player_html5_api")
var next_vid = document.createElement('video');

next_vid.innerHTML = '<source src="' + link + '" type="video/mp4">';
next_vid.muted = false;

current_vid.parentNode.replaceChild( next_vid, current_vid );

videojs(current_vid, {}, function(){
  // do something when video.js is ready
});
var current\u vid=document.getElementById(“vid-player\u html5\u api”)
var next_vid=document.createElement('video');
next_vid.innerHTML='';
next_vid.muted=false;
当前\u vid.parentNode.replaceChild(下一个\u vid,当前\u vid);
videojs(当前视频,{},函数(){
//当video.js准备就绪时执行一些操作
});

您可以按以下方式尝试

功能播放视频(视频源,类型){
var videoElm=document.getElementById('testVideo');
var videoSourceElm=document.getElementById('testVideoSource');
如果(!videoElm.暂停){
停顿;
}
videoSourceElm.src=视频源;
videoSourceElm.type=类型;
videoElm.load();
videoElm.play();
}


您可以按以下方式尝试

功能播放视频(视频源,类型){
var videoElm=document.getElementById('testVideo');
var videoSourceElm=document.getElementById('testVideoSource');
如果(!videoElm.暂停){
停顿;
}
videoSourceElm.src=视频源;
videoSourceElm.type=类型;
videoElm.load();
videoElm.play();
}



刚刚找到这篇文章,VideoJS中的当前模式是使用JSON对象设置.src

player.src({ type: 'video/mp4', src: new_url });

刚刚发现这篇文章,VideoJS中的当前模式是使用JSON对象设置.src

player.src({ type: 'video/mp4', src: new_url });

与我共事的唯一方式就是这样

var player = videojs(document.querySelector('.video-js'));
  player.src({
                src: 'videoURL,
                type: 'video/mp4'/*video type*/
            });

  player.play();

与我共事的唯一方式就是这样

var player = videojs(document.querySelector('.video-js'));
  player.src({
                src: 'videoURL,
                type: 'video/mp4'/*video type*/
            });

  player.play();

将所有代码放到jsfiddle将所有代码放到jsfiddle我认为.load()就可以做到这一点。load()是jQuery函数或内置视频。js函数load是视频内置函数。我没有在上面使用jquery,我认为.load()就可以做到这一点。load()是jQuery函数或内置视频。js函数load是视频内置函数。我没有使用上面的jquery