function attach(o,e,f){ if(o.attachEvent){ o.attachEvent('on'+e,f); }else{ o.addEventListener(e,f,false); } } function mp3player(s,fn,cf,cb,co,cl){ var mx; var my; var p=0; var cv = document.getElementById(s); if ( ! cv || ! cv.getContext ){ return false; } var ct = cv.getContext('2d'); ct.fillStyle=cb; ct.beginPath(); ct.fillRect(0,0,150,30); dDL(ct,cf); dST(ct,cf); dPL(ct,cf); dSL(ct,cf,p); var img=new Image(); img.src='http://radioybeat.net/img/player_logo.png'; img.onload=function() { ct.drawImage(img,100,22); } cv.onmousemove=mML; cv.onmouseup=mML; cv.onmousedown=mDL; cv.onmouseout=mOL; var np=0; var a=new Audio(fn); a.addEventListener('timeupdate',tUL,true); function mML(e) { getXY(e); if(my<18){ dSL(ct,cf,p); if(mx<18){ dDL(ct,co); dST(ct,cf); dPL(ct,cf); }else if(mx<36){ dDL(ct,cf); dST(ct,co); dPL(ct,cf); }else if(mx<54){ dDL(ct,cf); dST(ct,cf); dPL(ct,co); }else{ dDL(ct,cf); dST(ct,cf); dPL(ct,cf); } }else{ dDL(ct,cf); dST(ct,cf); dPL(ct,cf); if(mx<100){ dSL(ct,co,p); }else{ dSL(ct,cf,p); } } } function mDL(e) { getXY(e); if(my<18){ dSL(ct,cf,p); if(mx<18){ dDL(ct,cl); dST(ct,cf); dPL(ct,cf); window.location.href=fn.replace('http://radioybeat.net/','http://radioybeat.net/dl/'); }else if(mx<36){ dDL(ct,cf); dST(ct,cl); dPL(ct,cf); a.pause(); a.currentTime=0; np=0; }else if(mx<54){ dDL(ct,cf); dST(ct,cf); dPL(ct,cl); if(np>0){ a.pause(); np=0; }else{ a.play(); np=1; } }else{ dDL(ct,cf); dST(ct,cf); dPL(ct,cf); } }else{ dDL(ct,cf); dST(ct,cf); dPL(ct,cf); if(mx<100){ p=(mx-5)/90; if(p<0){ p=0; } if(p>1){ p=1 } a.pause(); a.currentTime=a.duration*p; if(np>0){ a.play(); } dSL(ct,cl,p); }else{ dSL(ct,cf,p); } } } function mOL(e) { dDL(ct,cf); dST(ct,cf); dPL(ct,cf); dSL(ct,cf,p); } function tUL(){ p=a.currentTime/a.duration; dSL(ct,cf,p); var scs='0'+Math.floor(a.currentTime%60); var scm='0'+Math.floor(a.currentTime/60); var sts='0'+Math.floor(a.duration%60); var stm='0'+Math.floor(a.duration/60); dTM(ct,cf,scm.substr(scm.length-2,2)+":"+scs.substr(scs.length-2,2)+' ['+stm.substr(stm.length-2,2)+':'+sts.substr(sts.length-2,2) +']'); } function dDL(ct,c){ ct.fillStyle=cb; ct.beginPath(); ct.fillRect(0,0,18,18); ct.fillStyle=c; ct.beginPath(); ct.moveTo(2,2); ct.lineTo(9,15); ct.lineTo(16,2); ct.closePath(); ct.fill(); } function dST(ct,c){ ct.fillStyle=cb; ct.beginPath(); ct.fillRect(18,0,18,18); ct.fillStyle=c; ct.beginPath(); ct.fillRect(20,2,14,14); } function dPL(ct,c){ ct.fillStyle=cb; ct.beginPath(); ct.fillRect(36,0,18,18); ct.fillStyle=c; ct.beginPath(); if(np>0){ ct.fillRect(38,2,6,14); ct.beginPath(); ct.fillRect(46,2,6,14); }else{ ct.moveTo(38,2); ct.lineTo(52,9); ct.lineTo(38,15); ct.closePath(); ct.fill(); } } function dSL(ct,c,p0){ ct.fillStyle=cb; ct.beginPath(); ct.fillRect(0,18,100,12); ct.fillStyle=c; ct.beginPath(); ct.fillRect(5,23,90,2); ct.beginPath(); ct.fillStyle=cf; ct.arc(p0*90+5,24,4,0,Math.PI * 2,false); ct.fill(); } function dTM(ct,c,st){ ct.fillStyle=cb; ct.beginPath(); ct.fillRect(54,0,96,18); ct.fillStyle=c; ct.font='12px sans-serif'; ct.textAlign='right'; ct.textBaseline='bottom'; ct.fillText(st,148,16,92); } function getXY(e) { var rect=e.target.getBoundingClientRect(); mx=e.clientX-rect.left; my=e.clientY-rect.top; } }