HTML
<div id="html5videoplayer" style="font-family: Arial Unicode MS;">
<video id="videoarea" class="video-js vjs-default-skin" controls preload="none" data-setup="{}">
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type="video/mp4" />
</video>
</div>
<ul id="playlist">
<li data-loc="http://video-js.zencoder.com/oceans-clip.mp4" data-type="video/mp4">Oceans</li>
<li data-loc="http://html5videoformatconverter.com/data/images/happyfit2.mp4" data-type="video/mp4">Happy Feet</li>
<li data-loc="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4" data-type="video/mp4">Sintel</li>
<li data-loc="http://www.ioncannon.net/examples/vp8-webm/big_buck_bunny_480p.webm" data-type="video/webm">Big Buck Bunny</li>
</ul>
CSS
#playlist li {
color: blue;
text-decoration: underline;
}
#playlist li:hover {
color: black;
cursor: pointer;
}
的Javascript
function doPlayList(listID, playerID) {
var player = document.getElementById(playerID);
var video = player.getElementsByTagName("video")[0];
var s;
video.src = null;
video.setAttribute("data-count", 0);
video.addEventListener("ended", function (e) {
e.preventDefault();
s = this.getElementsByTagName("source")[0];
var c = parseInt(this.getAttribute("data-count")) + 1;
var item = document.getElementById("video" + c);
if (item === null) {
item = document.getElementById("video0");
c = 0;
}
s.src = item.getAttribute("data-loc");
s.type = item.getAttribute("data-type");
this.setAttribute("data-count", c);
this.setAttribute("autoplay", "autoplay");
this.load();
this.play();
});
var list = document.getElementById(listID);
var items = list.getElementsByTagName("li");
for (var i = 0; i < items.length; i++) {
var item = items[i];
item.id = "video" + i;
item.addEventListener("click", function (e) {
e.preventDefault();
var p = document.getElementById("html5videoplayer");
var v = p.getElementsByTagName("video")[0];
var s = p.getElementsByTagName("source")[0];
s.src = this.getAttribute("data-loc");
s.setAttribute("type", this.getAttribute("data-type"));
v.setAttribute("data-count", this.id.substr(5));
v.setAttribute("autoplay", "autoplay");
v.load();
v.play();
});
}
}
document.onready = doPlayList("playlist", "html5videoplayer");
試一試jsFiddle。
顯然不同,在這裏,不需要jQuery。如果您有任何問題,請告訴我。
編輯:更改了代碼,因此它使用source
元素和data-*
屬性。希望這可以幫助。
我真的很感激你的時間。它適用於Chrome和FF,但我的共享點站點僅限於IE8。我使用videojs的原因就是出於這個原因。我可以像這樣播放單個視頻:但隨着播放列表,它要求我下載,而不是在播放器中播放,我認爲它的可能性是因爲ie8不理解某些屬性? – Athapali
你應該更新你的原始問題,注意IE8的限制。我將不得不查看它以瞭解IE8需要什麼。 – Ally