小白想通过js动态设置video的播放地址,饶了一天,终于走出坑,下面是解决的方法
js中
var videoUrl=var videoUrl="/file/"+row.path.substring(row.path.lastIndexOf("\\")+1); //此处填写你的视频地址 alert("videoUrl==="+videoUrl); var myPlayer = videojs('my-video'); videojs("my-video").ready(function() { var myPlayer = this; myPlayer.src(videoUrl); /*动态设置video.js播放的地址。*/ myPlayer.autoplay(); }); jsp页面中
<div > <video id="my-video" class="video-js vjs-big-play-centered " width="800px" height="450" data-setup="{}"> <source src="" class="ms_4" type="video/mp4"> <p class="vjs-no-js"> To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a> </p></video> </div>