2013-11-26 3 views
1

sharepoint 사이트에서 videojs player를 구현하고 싶습니다. 나는 플레이어를위한 하나의 정적 비디오 소스로 비디오 플레이어를 설정할 수있었습니다. 이제 플레이어 옆에있는 비디오 URL 목록을 원합니다.이 플레이어는 동일한 플레이어에서 비디오를 클릭하여로드 할 수 있습니다. 뭔가 가까운 것이 여기에서 완료되었습니다 : http://jsfiddle.net/Barzi/Jzs6B/9/ videojs를 사용하지 않고.html5 videojs 재생 목록 설정

videojs 구현과 비슷한 기능을 수행하려면 어떻게해야합니까? http://jsfiddle.net/6nJ4z/

<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><a href="http://html5videoformatconverter.com/data/images/happyfit2.mp4">Happy Fit</a></li> 
    <li><a href="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4">Sintel</a></li>  
    <li><a href="http://www.ioncannon.net/examples/vp8-webm/big_buck_bunny_480p.webm">Big Buck Bunny</a></li> 
</ul> 

답변

1

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-* 특성을 사용하도록 코드가 변경되었습니다. 희망이 도움이됩니다.

+0

정말 고마워요. 그것은 크롬과 FF에 잘 작동하지만 내 셰어 포인트 사이트는 IE8로 제한됩니다. 왜 내가 videojs를 사용했는지 그 이유가있었습니다. 다음과 같이 단일 비디오를 재생할 수 있습니다. 재생 목록을 사용하면 플레이어에서 재생하지 않고 다운로드하도록 요청합니다. ie8은 속성의 일부를 이해하지 못하기 때문에 그 probly 생각 ?? – Athapali

+1

원래 질문을 업데이트하여 IE8 제한 사항을 기록해야합니다. 나는 IE8이 필요로하는 것을보기 위해 그것을 조사해야 할 것이다. – Ally

1

비디오 태그의 비디오는 javascript로 변경할 수 있습니다. 당신은 HREF를 제거하고, 예를 들어, 비디오의 ADRESS에 온 클릭 요소를 사용할 수 있습니다

<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><a href="#" onclick="PlayVideo('happyfit2.mp4')">Happy Fit 2</a></li> 
     <li><a href="#" onclick="PlayVideo('happyfit3.mp4')">Happy Fit 3</a></li> 
     <li><a href="#" onclick="PlayVideo('happyfit4.mp4')">Happy Fit 4</a></li> 
    </ul> 

<script type="text/javascript"> 
    var PlayVideo = function(videoSrc){ 
     $("#html5videoplayer").remove("source"); 
     var htmlVideo = '<source type="video/mp4" src="'+ videoSrc +'" />'; 
     $("#html5videoplayer").html(htmlVideo); 
    } 
</script> 
+0

바이올린으로 시도해 보셨습니까? 나는 그것이 항상 효과가 있을지 모르겠다. 'application/octet'을 반환했기 때문에 비슷한 것을 시도했을 때 오류가 발생했기 때문에 모든 비디오가'video/mp4 '유형이 아닙니다. – Ally

+0

간단한 예입니다. 개발자는 목표에 맞게 조정해야합니다. 이 코드는 테스트하지 않았지만 응용 프로그램에서 비슷한 코드를 사용했습니다. –

관련 문제