【www.gdgbn.com--html5教程】



ThreeAnts Player


words" content="Player,cdf,desktop toy">


<script language="JavaScript">
var scrollcount=0;
var dragy;
var scrollarrowtop;
function initdrag() {
 scrollcount=1;
 dragy=event.clientY;
 document.body.setCapture();
}
function startdrag() {
 if (scrollcount==1) {
  window.scrollBy(0,dragy-event.clientY);
  document.body.style.cursor="hand";
  dragy=event.clientY;
 }
}
function enddrag() {
 document.body.style.cursor="";
 scrollcount=0;
 document.body.releaseCapture();
}
</script>
scroll=no
ondragstart = "return false;"
onselect = "return false;"
onselectstart="return false;"
onmousedown="initdrag()"
onmousemove="startdrag()"
onmouseup="enddrag()"
>
<script>
var PlayType = ",wma,wmv,avi,mpg,mpeg,m1v,mp2,wav,mp3"
var nowPlayingID
var lastSelected
var lastPlayed

var si = setInterval("Timer()",1000)
function Timer(){
 percent.innerHTML = Math.round((Player.currentposition/Player.selectionend)*100)+"%"
 ttt.style.width = Math.round((Player.currentposition/Player.selectionend)*100)+"%"
 if((Player.currentposition >= Player.selectionend) && Player.currentposition!=0){
  clearInterval(si)
  playNextMusic()
  si = setInterval("Timer()",1000)
 }
}
function mute(){
 Player.mute = !Player.mute
}
//检测载入的文件类型
function CheckType(){
 var s = FileObj.value.split(".");
 return PlayType.indexOf(s[s.length-1].toLowerCase())>0?true:false;
}
// open
function openMusic(){
  FileObj.click();
  if(FileObj.value != "" && CheckType()){
   FileObj.value.replace("\","\\");
   addMusic(FileObj.value);
   FileObj.value = "";
  }
}
// Add music
function addMusic(musicSrc){
 var newTR=playListTable.insertRow();
 var newTD=newTR.insertCell();
 newTR.className = "content";
 newTR.onclick = function(){
  if (lastSelected != null){
   lastSelected.className = "content"
  }
  this.className = "hilite_content"
  lastSelected = this
 }
 newTD.ondblclick = function(){
  playMusic(this.id)
 }
 newTD.oncontextmenu = function(){
  playListTable.deleteRow(this.parentElement.rowIndex)
 }
 musicTitle = musicSrc.split("\");
 musicTitle = musicTitle[musicTitle.length-1].split(".");
 musicTitle = musicTitle.slice(0,musicTitle.length-1);
 newTD.innerHTML = musicTitle
 newTD.musicName = musicTitle
 newTD.musicSrc  = musicSrc
 newTD.id  = "m" + newTR.rowIndex
}
// play
function playMusic(id,currentposition){
 if (lastPlayed != null){
  lastPlayed.innerHTML = lastPlayed.musicName
 }
 if(!document.all[id]){
  id = "m1"
 }
 TD = eval(id)
 TD.innerHTML += " "
 lastPlayed = TD
 Player.filename = TD.musicSrc
 nowPlayingID = id
 Player.currentposition = (currentposition == undefined) ? 2 : currentposition
}
// play next music
function playNextMusic(){
 Player.stop()
 newID = parseInt(nowPlayingID.replace("m",""))+1
 playMusic("m"+newID)
}
// play prev music
function playPrevMusic(){
 Player.stop()
 newID = parseInt(nowPlayingID.replace("m",""))-1
 playMusic("m"+newID)
}
// cookie
function saveCookie(name,value,days) {
 if (days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000))
  var expires = "; expires="+date.toGMTString()
 }
 else expires = ""
 document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
 var nameEQ = name + "="
 var ca = document.cookie.split(";")
 for(var i=0;i   var c = ca[i];
  while (c.charAt(0)==" ") c = c.substring(1,c.length)
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
 }
 return null
}
function deleteCookie(name) {
 saveCookie(name,"",-1)
}
// Load play list from Cookie
window.onload = function(){
 cookiePlayList = readCookie("cookiePlayList")
 cookiePlayList = cookiePlayList.split(",");
 for(x in cookiePlayList){
  addMusic(cookiePlayList[x])
 }
 cookieNowPlayingID = readCookie("cookieNowPlayingID")
 cookieCurrentposition = readCookie("cookieCurrentposition")
 playMusic(cookieNowPlayingID,cookieCurrentposition)
}
// Save play list & now playing
window.onunload = function(){
 if(Player.filename!="" && Player.filename!=null){
  saveCookie("cookieNowPlayingID",nowPlayingID,100)
  saveCookie("cookieCurrentposition",Player.currentposition,100)
 }
 var playList = new Array()
 for(i=1;i   playList.push(playListTable.rows[i].cells[0].musicSrc)
 }
 saveCookie("cookiePlayList",playList,100)
}
window.onerror = function(){
 return true;
}
</script>

 
  
   open
    | prev
    | play
    | pause
    | stop
    | next
   
  
 


 
  
  
 


 



本文来源:http://www.gdgbn.com/wangyezhizuo/11176/