<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="skins/JinnStyleV1/article.xslt"?><blog view="686736" processed="0.128" queries="8" focusMarkup="" xslt="skins/JinnStyleV1/article.xslt"><panels><panel id="1" sn="0" sys="true"><name>Blog Main</name><content><article id="181" disComm="false"><title>[JavaScript]网页中音乐LRC歌词同步显示</title><category id="20"><name>学习随笔</name><icon>images/icons/3.gif</icon></category><content><![CDATA[<img src='http://www.iscripts.org/data/attachment/forum/month_1104/11041323240bab7833cf35aaf1.jpg' border='0' /><br /><br /><textarea name='code' class='js' cols='50'>function LRCPlayer(wmp, strLRC, container, width, height, color1, color2) {
    this.wmp = wmp;
    this.height = height;
    
    this.checkInterval = 0;
    this.transInterVal = 0;
    this.currentFocus  = -1;
    
    var ls = this.ls = this.parseLRC(strLRC);
    var div = document.createElement('div');
    div.style.cssText = &quot;display:block;width:&quot;+width+&quot;px; height:&quot; + height + &quot;px; overflow:hidden; background:#000;&quot;;
    var lrcPanel = this.lrcPanel = document.createElement('div');
    div.appendChild(lrcPanel);
    container.appendChild(div);
    this.colorTrans = this.colorCal(color1, color2);
    this.color1 = color1;
    var span = document.createElement('div');
    span.style.cssText = &quot;height:&quot; + (height/2) + &quot;px;&quot;;
    lrcPanel.appendChild(span);
    for (var i=0; i&lt;ls.length; i++) {
        span = document.createElement('div');
        span.style.cssText = 'font-size:12px; height:16px; line-height:16px; text-align:center; overflow: hidden; white-space: nowrap; color:#' + color1;
        span.appendChild(document.createTextNode(ls<i>.text));
        lrcPanel.appendChild(span);
    }
    span = document.createElement('div');
    span.style.cssText = &quot;height:&quot; + (height/2) + &quot;px;&quot;;
    lrcPanel.appendChild(span);
    this.start();
}

$.extend(LRCPlayer.prototype, {
    start: function() {
        var me = this;
        !function() {
            setTimeout(arguments.callee, 128);
            me.checkPos();
        }();
    }
    , stop: function() {
        if (this.checkInterval)
            clearTimeout(this.checkInterval);
    }
    , checkPos: function() {
        try {
            var cPos = this.wmp.controls.currentPosition;
            if (isNaN(cPos)) return;
            if (this.currentFocus&lt;this.ls.length-1 &amp;&amp; cPos &gt; this.ls[this.currentFocus+1].pos) {
                this.focusThis(this.currentFocus+1);
            } else if (this.currentFocus&gt;-1 &amp;&amp; cPos&lt;this.ls[this.currentFocus].pos) {
                this.focusThis(this.currentFocus-1);
            }
            if (this.currentFocus &gt;= this.ls.length-1) return;
            var pos = this.ls[this.currentFocus].pos;
            var nPos = this.ls[this.currentFocus+1].pos;
            var lrct = (cPos - pos)/(nPos - pos);
            lrct = Math.max(Math.min(lrct, 1), 0);
            this.lrcPanel.parentNode.scrollTop = (this.currentFocus+lrct) * 16;
        } catch(e) { }
    }
    , focusThis: function(index) {
        if (this.transInterVal) {
            clearTimeout(this.transInterVal);
        }
        if (this.currentFocus &gt; -1) {
            this.lrcPanel.childNodes[this.currentFocus+1].style.color = '#'+this.color1;
        }
        this.currentFocus = index;
        var me = this;
        var i = 0;
        !function() {
            if (i&gt;=8) return;
            me.lrcPanel.childNodes[me.currentFocus+1].style.color = '#' + me.colorTrans[i++];
            me.transInterVal = setTimeout(arguments.callee, 128);
        }();
    }

    , colorCal: function(c1, c2) {
        var oC2 = c2;
        c1 = parseInt(c1, 16); c2 = parseInt(c2, 16);
        var r1 = c1 &gt;&gt; 16, g1 = (c1 &gt;&gt; 8) &amp; 0xff; b1 = c1 &amp; 0xff;
        var r2 = c2 &gt;&gt; 16, g2 = (c2 &gt;&gt; 8) &amp; 0xff; b2 = c2 &amp; 0xff;
        var cs = [], d1 = r2 - r1, d2 = g2 - g1, d3 = b2 - b1, r, g, b;
        for (var i=1; i&lt;8; i++) {
            r = r1+parseInt(Math.round(d1*i*0.125, 0));
            g = g1+parseInt(Math.round(d2*i*0.125, 0));
            b = b1+parseInt(Math.round(d3*i*0.125, 0));
            cs.push( (&quot;00000&quot;+((r&lt;&lt;16)|(g&lt;&lt;8)|b).toString(16)).slice(-6) );
        }
        return cs.concat(oC2);
    }
    
    , parseLRC: function(str) {
        var map = {'ti':'&#26631;&#39064;&#65306;', 'ar':'&#33402;&#26415;&#23478;&#65306;', 'al':'&#19987;&#36753;&#65306;', 'by':'&#27468;&#35789;&#21046;&#20316;&#65306;'};
        str = str.replace(/\[(ti|ar|al|by):([^[\]]*)\]/ig, function($, $1, $2) {
            return '[00:00.00]' + (map[$1.toLowerCase()]||'') + $2;
        });
        var offset = 0;
        str = str.replace(/\[offset:(-?\d+)\]/gi, function($, $1) {
            offset = parseInt($1, 10) * 0.001;
        });
        var regex1 = /(\[[^[\]]+\])(\[[^[\]]+\])([^[\]]*?)$/m;
        var regex2 = /(\[[^[\]]+\])(\[[^[\]]+\])([^[\]]*?)$/mg;
        while (regex1.test(str)) {
            str = str.replace(regex2, &quot;$1$3\n$2$3&quot;);
        }
        var ls = [];
        str.replace(/\[(\d+):([\d.]+)\](.*)/g, function($, $1, $2, $3) {
            ls.push({ pos:parseInt($1,10)*60+parseFloat($2,10)*1+offset, text:$3 });
        });
        ls.sort(function(a, b) {
            return a.pos-b.pos;
        });
        return ls;
    }
});

</textarea><br /><br />&#19978;&#38754;&#26159;&#19981;&#23436;&#25972;&#20195;&#30721;<br />&#20855;&#20307;&#20351;&#29992;&#20363;&#23376;&#19979;&#36733;&#35265;:<br /><a href='http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=49' target='_blank'>http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=49</a><br /><br />&#38468;&#65306;<br />ASP/jscript &#20174;&#21315;&#21315;&#38745;&#21548;&#30340;&#27468;&#35789;&#26381;&#21153;&#22120;&#26597;&#35810;&#38899;&#20048;&#30340; LRC &#27468;&#35789;<br /><a href='http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=86' target='_blank'>http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=86</a><br /><br />[Java] &#20174;&#21315;&#21315;&#38745;&#21548;&#30340;&#27468;&#35789;&#26381;&#21153;&#22120;&#26597;&#35810;&#38899;&#20048;&#30340; LRC &#27468;&#35789;<br /><a href='http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=85' target='_blank'>http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=85</a>]]></content><publish>2011-05-13 17:08:26</publish><update>2011-06-30 11:30:47</update><comment>1</comment><view>2709</view></article><comments><comment id="269"><usn>jiwei</usn><publish>2011-10-23 14:45:07</publish><content>&amp;#20855;&amp;#20307;&amp;#24590;&amp;#26679;&amp;#23454;&amp;#29616;&amp;#21834; &amp;#33021;&amp;#25945;&amp;#25945;&amp;#25105;&amp;#22043; &amp;#25105;QQ&amp;#65306;1186923904</content><reply></reply></comment></comments><previous id="180"><title>从千千静听的歌词服务器查询音乐的 LRC 歌词 [Java]</title></previous><next id="182"><title>ASP 怎样把数据库查询结果保存到 excel 文件中</title></next></content></panel></panels><modules><module id="4" sn="3" sys="true"><name>Category</name><title>日志分类</title></module><module id="6" sn="4" sys="true"><name>Archive</name><title>日志归档</title></module><module id="5" sn="5" sys="true"><name>User Panel</name><title>控制面板</title></module><module id="10" sn="6" sys="true"><name>Recent Article</name><title>最新日志</title></module><module id="8" sn="7" sys="true"><name>Search</name><title>查询搜索</title></module><module id="7" sn="8" sys="true"><name>Recent Comments</name><title>最新评论</title></module><module id="2" sn="9" sys="true"><name>Statistics</name><title>统计信息</title></module></modules><user><usn></usn><status>3</status><login>false</login></user></blog>
