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;
}
자바 스크립트
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-*
특성을 사용하도록 코드가 변경되었습니다. 희망이 도움이됩니다.
정말 고마워요. 그것은 크롬과 FF에 잘 작동하지만 내 셰어 포인트 사이트는 IE8로 제한됩니다. 왜 내가 videojs를 사용했는지 그 이유가있었습니다. 다음과 같이 단일 비디오를 재생할 수 있습니다. 재생 목록을 사용하면 플레이어에서 재생하지 않고 다운로드하도록 요청합니다. ie8은 속성의 일부를 이해하지 못하기 때문에 그 probly 생각 ?? – Athapali
원래 질문을 업데이트하여 IE8 제한 사항을 기록해야합니다. 나는 IE8이 필요로하는 것을보기 위해 그것을 조사해야 할 것이다. – Ally