HTML5视频播放器控件在Chrome中无效

时间:2017-02-22 09:34:30

标签: javascript html css html5 video

代码段:在页面加载的javascript中创建视频播放器元素

videoplayer = document.createElement("video");
videoplayer.setAttribute("id","myVideoPlayer");
videoplayer.setAttribute("controls","controls");
videoplayer.setAttribute("style","display:none");
videoplayer.setAttribute("width","200");
videoplayer.setAttribute("height", "200");
videosource = document.createElement("source");
videosource.type = "video/mp4";

videoplayer.appendChild(videosource);

containerDiv.appendChild(videoplayer);

以及用户点击事件我正在更改视频播放器的来源

videoplayer = document.getElementById("myVideoPlayer");


var videosource= videoplayer.getElementsByTagName('source');
videosource = videosource[0]
videosource.src = "my video url comes here";
videosource.type = "video/mp4";

videoplayer.pause();    
videoplayer.load();
videoplayer.play();

如果我向前和向后做,它仍然从我们离开的地方开始。

1 个答案:

答案 0 :(得分:0)

您必须更改videoplayer元素的src,而不是videosource元素。

所以,代码将是

videoplayer.setAttribute("src", "your video path");