页面演示:http://bidwy.lingd.net/article-1898317-1.html
百度搜索:http://www.baidu.com/s?wd=%D4%DA%CF%DF%B2%A5%B7%C5+%B8%E8%B4%CA%B6%D4%D5%D5+%B4%FA%C2%EB
<script language=”JavaScript”>
// 为了兼容 IE5.0 结果好多正则的语法和处理方式都不能用,所以代码效率不是最高,郁闷。
function lrcClass(tt) //LRC歌词处理 类
{
this.gsh=”歌手:~1~\n曲名:~2~\n专辑:~3~\n编者:~4~”;
this.inr = []; //行
this.oTime = 0; //余补时间
this.hailang;
this.dts = -1; //当前行显示的s
this.dte = -1; //当前行显示的e
this.dlt = -1; //当前行
this.ddh; //当前行数据
this.fjh;
this.haohaiplay;
this.oceanx;
this.cnane;
//以上几个属性是为了判断是否还在上次显示的时间范围,以减少循环次数
if(/\[offset\:(\-?\d+)\]/i.test(tt)) //取offset余补时间
this.oTime = RegExp.$1/1000;
this.gsh = this.gsh.replace(“~1~”,(/\[ar:([^\[\]:]+)\]/i.test(tt))?RegExp.$1:”—-“);
this.gsh = this.gsh.replace(“~2~”,(/\[ti:([^\[\]:]+)\]/i.test(tt))?RegExp.$1:”—-“);
this.gsh = this.gsh.replace(“~3~”,(/\[al:([^\[\]:]+)\]/i.test(tt))?RegExp.$1:”—-“);
this.gsh = this.gsh.replace(“~4~”,(/\[by:([^\[\]:]+)\]/i.test(tt))?RegExp.$1:”—-“);
lrcxx.innerText = this.gsh;
tt = tt.replace(/\[\:\][^$\n]*(\n|$)/g,”$1″); //去掉注解
tt = tt.replace(/\[[^\[\]\:]*\]/g,””);
tt = tt.replace(/\[[^\[\]]*[^\[\]\d]+[^\[\]]*\:[^\[\]]*\]/g,””);
tt = tt.replace(/\[[^\[\]]*\:[^\[\]]*[^\[\]\d\.]+[^\[\]]*\]/g,””);
tt = tt.replace(/<[^<>]*[^<>\d]+[^<>]*\:[^<>]*>/g,””);
tt = tt.replace(/<[^<>]*\:[^<>]*[^<>\d\.]+[^<>]*>/g,””); //去掉除时间标签的其它标签
while(/\[[^\[\]]+\:[^\[\]]+\]/.test(tt))
{
tt = tt.replace(/((\[[^\[\]]+\:[^\[\]]+\])+[^\[\r\n]*)[^\[]*/,”\n”);
var zzzt = RegExp.$1;
/^(.+\])([^\]]*)$/.exec(zzzt);
var ltxt = RegExp.$2;
var eft = RegExp.$1.slice(1,-1).split(“][“);
for(var ii=0; ii<eft.length; ii++)
{
var sf = eft[ii].split(“:”);
var tse = parseInt(sf[0],10) * 60 + parseFloat(sf[1]);
var sso = { t:[] , w:[] , n:ltxt }
sso.t[0] = tse-this.oTime;
this.inr[this.inr.length] = sso;
}
}
this.inr = this.inr.sort( function(a,b){return a.t[0]-b.t[0];} );
for(var ii=0; ii<this.inr.length; ii++)
{
while(/<[^<>]+\:[^<>]+>/.test(this.inr[ii].n))
{
this.inr[ii].n = this.inr[ii].n.replace(/<(\d+)\:([\d\.]+)>/,”%=%”);
var tse = parseInt(RegExp.$1,10) * 60 + parseFloat(RegExp.$2);
this.inr[ii].t[this.inr[ii].t.length] = tse-this.oTime;
}
lrcbc.innerHTML = “<font>”+ this.inr[ii].n.replace(/&/g,”&”).replace(/</g,”<”).replace(/>/g,”>”).replace(/%=%/g,”</font><font>”) +” </font>”;
var fall = lrcbc.getElementsByTagName(“font”);
for(var wi=0; wi<fall.length; wi++)
this.inr[ii].w[this.inr[ii].w.length] = fall[wi].offsetWidth;
this.inr[ii].n = lrcbc.innerText;
}
this.print(“”);
lrcwt1.innerText = “”;
lrcwt2.innerText = “”;
lrcwt3.innerText = “”;
lrcwt4.innerText = “”;
lrcwt5.innerText = “”;
lrcbc.style.width = 0;
}
lrcClass.prototype.run = function()
{
try {
if(this.oceanx==0)
this.runing(this.haohaiplay.controls.currentPosition, this.haohaiplay.currentMedia.duration);
else
this.runing(this.haohaiplay.GetPosition()/1000, this.haohaiplay.GetLength()/1000);
} catch(hh){}
}
lrcClass.prototype.runing = function(tme, plen)
{
if(tme<this.dts || tme>=this.dte)
{
var ii;
for(ii=this.inr.length-1; ii>=0 && this.inr[ii].t[0]>tme; ii–){}
if(ii<0) return;
this.ddh = this.inr[ii].t;
this.fjh = this.inr[ii].w;
this.dts = this.inr[ii].t[0];
this.dte = (ii<this.inr.length-1)?this.inr[ii+1].t[0]:plen;
lrcwt1.innerText = this.retxt(ii-3);
lrcwt2.innerText = this.retxt(ii-2);
lrcwt3.innerText = this.retxt(ii-1);
lrcwt4.innerText = this.retxt(ii+1);
lrcwt5.innerText = this.retxt(ii+2);
this.print(this.retxt(ii));
if(this.dlt==ii-1)
{
clearTimeout(this.hailang);
this.golrcoll(0);
}
this.dlt = ii;
}
var bbw = 0;
var ki;
for(ki=0; ki<this.ddh.length && this.ddh[ki]<=tme; ki++)
bbw += this.fjh[ki];
var kt = ki-1;
var sc = ((ki<this.ddh.length)?this.ddh[ki]:this.dte) – this.ddh[kt];
var tc = tme – this.ddh[kt];
bbw -= this.fjh[kt] – tc / sc * this.fjh[kt];
if(bbw>lrcbox.offsetWidth)
bbw = lrcbox.offsetWidth;
lrcbc.style.width = Math.round(bbw);
}
lrcClass.prototype.retxt = function(i)
{
return (i<0 || i>=this.inr.length)?””:this.inr[i].n;
}
lrcClass.prototype.print = function(txt)
{
lrcbox.innerText = txt;
lrcbc.innerText = txt;
}
lrcClass.prototype.golrcoll = function(s)
{
lrcoll.style.top = 25-(s++)*5;
lrcwt1.filters.alpha.opacity = 90-s*18;
lrcwt5.filters.alpha.opacity = s*18+10;
if(s<=5)
this.hailang = setTimeout(this.cnane+”.golrcoll(“+s+”)”,120);
}
////////////////////////////////////////////////////////////////////
var lrcobj;
function play()
{
var m = lrcdata.innerHTML.slice(4,-3);
lrcobj = new lrcClass(m);
lrcobj.cnane = “lrcobj”;
lrcobj.haohaiplay = mediaPlayerObj;
lrcobj.oceanx = 0;
//0为使用 Media Player 控件,1为使用 Real Player 控件
setInterval(“lrcobj.run();”,100);
}
</script>
——————————————
<span id=”lrcdata”><!–
[ti:日不落]
[ar:蔡依林]
[al:特务J]
[by:李泽昊]
[00:02.00]蔡依林 – 日不落
[00:24.80]
[00:24.87]天空的雾来的漫不经心
[00:28.85]河水像油画一样安静
[00:32.33]和平鸽慵懒步伐咬着云
[00:36.29]心偷偷的放晴
[00:38.07]
[00:39.97]祈祷你像英勇的禁卫军
[00:43.84]动也不动的守护爱情
[00:47.34]你在回忆里留下的脚印
[00:51.28]是我爱的风景
[00:52.98]
[00:54.95]我要送你 日不落的想念
[00:58.78]寄出代表爱的明信片
[01:02.67]我要送你 日不落的爱恋
[01:06.22]紧牵着心把世界走遍
[01:09.61]
[01:10.19]你就是晴天 你就是晴天
[01:13.77]我的爱未眠
[01:17.56]不落的想念 飞在你身边
[01:21.25]我的爱未眠
[01:23.65]
[01:25.39]爱的巴士总是走了又停
[01:28.78]微笑望着广场上人群
[01:32.47]我要把爱全都装进心里
[01:36.27]陪我一起旅行
[01:38.26]
[01:39.75]我要送你 日不落的想念
[01:43.66]寄出代表爱的明信片
[01:47.52]我要送你 日不落的爱恋
[01:51.19]紧牵着心 把世界走遍
[01:54.71]
[01:55.18]你就是晴天 你就是晴天
[01:58.83]我的爱未眠
[02:02.73]不落的想念 飞在你身边
[02:06.33]我的爱未眠
[02:09.20]
[02:10.20]
[02:16.00]
[02:24.00]
[02:25.36]祈祷你像英勇的禁卫军
[02:28.87]动也不动的守护爱情
[02:32.40]你在回忆里留下的脚印
[02:36.33]是我爱的风景
[02:38.21]
[02:39.81]我要送你 日不落的想念
[02:43.74]寄出代表爱的明信片
[02:47.55]我要送你 日不落的爱恋
[02:51.06]紧牵着心把世界走遍
[02:54.73]
[02:54.98]你就是晴天 你就是晴天
[02:58.65]我的爱未眠
[03:02.45]不落的想念 飞在你身边
[03:06.12]我的爱未眠
[03:08.26]
[03:10.31]我要送你 日不落的想念
[03:13.67]寄出代表爱的明信片
[03:17.47]我要送你 日不落的爱恋
[03:21.17]紧牵着心把世界走遍
[03:24.62]
[03:25.03]你就是晴天 你就是晴天
[03:28.65]我的爱未眠
[03:32.40]不落的想念 飞在你身边
[03:36.16]我的爱未眠
[03:39.67]–></span>