<html><head>
<meta http-equiv=Content-Type content=text/html; charset=utf-8>
<title>音樂歌詞同步測(cè)試--建站學(xué)(
www.jzxue.com)</title>
<style>
<!--
.div
{
width:460px;
height:200px;
overflow-y:scroll;
padding-top:80px;
text-align:left;
padding-left:100px;
line-height:25px;
font-size:13px;
padding-bottom:50px;
}
-->
</style>
<script language="javascript">
var scrollt=0;
var tflag=0;//存放時(shí)間和歌詞的數(shù)組的下標(biāo)
var lytext=new Array();//放存漢字的歌詞
var lytime=new Array();//存放時(shí)間
var delay=10;
var line=0;
var scrollh=0;
function getLy()//取得歌詞
{
var ly="[00:00]21個(gè)人.[00:10]制作:小黑.[00:20]歌手:游鴻明.[02:02][00:24]沒想到是你.[00:29]看著,想著,說著失去.[02:12][00:35]想結(jié)束關(guān)系,又覺得可惜.[02:20][00:44]你紅著雙眼,試著,做著,想著改變. [02:30][00:54]但激情沉淀,結(jié)局更明顯.[02:41][01:04]我看過溫柔凋萎.[02:46][01:09]也聽過諾言. [02:48][01:11]似玻璃破碎.[02:50]][01:14]我看過情人憔悴.[02:56][01:19]就好像刺猬為分離流淚. [03:00][01:23]傷心人負(fù)心人.[03:03][01:26]天下人癡情人.[03:05][01:28]只要是被傷心的人喝一杯. [01:33]自已人愛別人.[01:36]什么人狠心人.[01:38]不要再等,喝醉的靈魂.[03:46][01:45]music……. [02:06]談著想著說著失去.[03:10]自已人愛別人.[03:12]什么人狠心人.[03:15]不要再等.[03:18]喝醉的靈魂. [03:56][03:23]多情人無心人.[03:59][03:25]無情人多傷人.[04:01][03:28]只要是被傷心的人喝一杯. [04:06][03:32]有心人無緣人.[04:08][03:34]有緣人斷腸人.[04:11][03:37]何必再問新人換舊人. [04:20]music again……."
return ly;
}
function show(t)//顯示歌詞
{
var div1=document.getElementById("lyr");//取得層
document.getElementById("lyr").innerHTML=" ";//每次調(diào)用清空以前的一次
if(t<lytime[lytime.length-1])//先舍棄數(shù)組的最后一個(gè)
{
for(var k=0;k<lytext.length;k++)
{
if(lytime[k]<=t&&t<lytime[k+1])
{
scrollh=k*25;//讓當(dāng)前的滾動(dòng)條的頂部改變一行的高度
div1.innerHTML+="<font color=red style=font-weight:bold>"+lytext[k]+"</font><br>";
}
else if(t<lytime[lytime.length-1])//數(shù)組的最后一個(gè)要舍棄
div1.innerHTML+=lytext[k]+"<br>";
}
}
else//加上數(shù)組的最后一個(gè)
{
for(var j=0;j<lytext.length-1;j++)
div1.innerHTML+=lytext[j]+"<br>";
div1.innerHTML+="<font color=red style=font-weight:bold>"+lytext[lytext.length-1]+"</font><br>";
}
}
function scrollBar()//設(shè)置滾動(dòng)條的滾動(dòng)
{
if(document.getElementById("lyr").scrollTop<=scrollh)
document.getElementById("lyr").scrollTop+=1;
if(document.getElementById("lyr").scrollTop>=scrollh+50)
document.getElementById("lyr").scrollTop-=1;
window.setTimeout("scrollBar()",delay);
}
function getReady()//在顯示歌詞前做好準(zhǔn)備工作
{
var ly=getLy();//得到歌詞
//alert(ly);
var arrly=ly.split(".");//轉(zhuǎn)化成數(shù)組
for(var i=0;i<arrly.length;i++)
sToArray(arrly[i]);
sortAr();
/*for(var j=0;j<lytext.length;j++)
{
document.getElementById("lyr").innerHTML+=lytime[j]+lytext[j]+"<br>";
}*/
scrollBar();
}
function sToArray(str)//解析如“[02:02][00:24]沒想到是你”的字符串前放入數(shù)組
{
var left=0;//"["的個(gè)數(shù)
var leftAr=new Array();
for(var k=0;k<str.length;k++)
{
if(str.charAt(k)=="[")
{
leftAr[left]=k;
left++;
}
}
if(left!=0)
{
for(var i=0;i<leftAr.length;i++)
{
lytext[tflag]=str.substring(str.lastIndexOf("]")+1);//放歌詞
lytime[tflag]=conSeconds(str.substring(leftAr[i]+1,leftAr[i]+6));//放時(shí)間
tflag++;
}
}
//alert(str.substring(leftAr[0]+1,leftAr[0]+6));
}
function sortAr()//按時(shí)間重新排序時(shí)間和歌詞的數(shù)組
{
var temp=null;
var temp1=null;
for(var k=0;k<lytime.length;k++)
{
for(var j=0;j<lytime.length-k;j++)
{
if(lytime[j]>lytime[j+1])
{
temp=lytime[j];
temp1=lytext[j];
lytime[j]=lytime[j+1];
lytext[j]=lytext[j+1];
lytime[j+1]=temp;
lytext[j+1]=temp1;
}
}
}
}
function conSeconds(t)//把形如:01:25的時(shí)間轉(zhuǎn)化成秒;
{
var m=t.substring(0,t.indexOf(":"));
var s=t.substring(t.indexOf(":")+1);
s=parseInt(s.replace(/\b(0+)/gi,""));
if(isNaN(s))
s=0;
var totalt=parseInt(m)*60+s;
//alert(parseInt(s.replace(/\b(0+)/gi,"")));
if(isNaN(totalt))
return 0;
return totalt;
}
function getSeconds()//得到當(dāng)前播放器播放位置的時(shí)間
{
var t=getPosition();
t=t.toString();//數(shù)字轉(zhuǎn)換成字符串
var s=t.substring(0,t.lastIndexOf("."));//得到當(dāng)前的秒
//alert(s);
return s;
}
function getPosition()//返回當(dāng)前播放的時(shí)間位置
{
var mm=document.getElementById("MediaPlayer1");
//var mmt=;
//alert(mmt);
return mm.CurrentPosition;
}
function mPlay()//開始播放
{
var ms=parseInt(getSeconds());
if(isNaN(ms))
show(0);
else
show(ms);
window.setTimeout("mPlay()",100)
}
window.setTimeout("mPlay()",100)
function test()//測(cè)試使用,
{
alert(lytime[lytime.length-1]);
}
</script>
</head>
<body onLoad="getReady()">
<object id="MediaPlayer1" width="460" height="68" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
codebase="
type="application/x-oleobject">
<param name="FileName" value="<param name="ShowControls" value="1">
<param name="ShowPositionControls" value="0">
<param name="ShowAudioControls" value="1">
<param name="ShowTracker" value="1">
<param name="ShowDisplay" value="0">
<param name="ShowStatusBar" value="1">
<param name="AutoSize" value="0">
<param name="ShowGotoBar" value="0">
<param name="ShowCaptioning" value="0">
<param name="AutoStart" value="1">
<param name="PlayCount" value="0">
<param name="AnimationAtStart" value="0">
<param name="TransparentAtStart" value="0">
<param name="AllowScan" value="0">
<param name="EnableContextMenu" value="1">
<param name="ClickToPlay" value="0">
<param name="InvokeURLs" value="1">
<param name="DefaultFrame" value="datawindow">
<embed src="type="application/x-mplayer2"
pluginspage="showaudiocontrols="1" showtracker="1" showdisplay="0"
showstatusbar="1"
autosize="0"
showgotobar="0" showcaptioning="0" autostart="1" autorewind="0"
animationatstart="0" transparentatstart="0" allowscan="1"
enablecontextmenu="1" clicktoplay="0" invokeurls="1"
defaultframe="datawindow">
</embed>
</object>
<div id=lyr class=div>歌詞加載中……</div>
</body>
</html>