2011年8月30日星期二

Youtube API Chromeless Player

youtube api 的教學,極混亂,自己記錄一個。
 Chromeless Player 最簡單的實作,不包含CSS修飾。


<HEAD>部分
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function onYouTubePlayerReady(playerID){
  ytplayer=document.getElementById("myytplayer");
}
function play(){
  if(ytplayer){
    ytplayer.playVideo();
  }
}
function pause(){
  if(ytplayer){
    ytplayer.pauseVideo();
  }
}
function stop(){
  if(ytplayer){
    ytplayer.stopVideo();
  }
}
function mute(){
  if(ytplayer){
    ytplayer.mute();
  }
}
function unMute(){
  if(ytplayer){
    ytplayer.unMute();
  }
}
</script>
<BODY>部分
 <script type="text/javascript">
         var params={allowScriptAccess:"always"};
         var atts={id:"myytplayer"};
         swfobject.embedSWF("http://www.youtube.com/apiplayer?video_id=xvbjkniZYbI&version=3&enablejsapi=1&playerapiid=ytplayer",
                    "ytapiplayer","505","255","8",null,null,params,atts) ;
 </script>

<a href="javascript:void(0);" onclick="play();">Play |</a>
<a href="javascript:void(0);" onclick="pause();">Pause |</a>
<a href="javascript:void(0);" onclick="stop();">Stop |</a>
<a href="javascript:void(0);" onclick="mute();">Mute </a>
<a href="javascript:void(0);" onclick="unMute();">Unmute </a>