由zas研发的s2 music player LRC歌词原理(由zas本人提供):
//--接口--
function loadLRC(path) {
delete this.onEnterFrame;
lrcData.timer = new Array();
lrcData.info = new Array();
myCodePage = System.useCodepage;
System.useCodepage = true;
isLRCShow = false;
mc_lrc.tx_lrc.htmlText = " ";
mc_lrc.tx_lrc.setTextFormat(lrcFormat);
trace("LRC文档地址:" path);
lrcFile.load(path);
mc_loadEvent.onEnterFrame = function() {
if (lrcFile.getBytesLoaded()>10) {
var per = Math.floor(lrcFile.getBytesLoaded()/lrcFile.getBytesTotal()*100);
mc_lrc.tx_lrc.htmlText = "
" "正在下载歌词.." per "%";
} else {
mc_lrc.tx_lrc.htmlText = "
" "正在查找歌词.." "";
}
mc_lrc.tx_lrc.setTextFormat(lrcFormat);
};
}
//
//读取LRC文本流
lrcFile = new XML();
lrcFile.onLoad = function(success) {
if (success) {
trace(true);
myLRC = this.toString();
myLRC = myLRC.slice(myLRC.indexOf("["));
initLRC();
} else {
trace("LRC LoadError");
mc_lrc.tx_lrc.htmlText = "
" "未加载歌词" "";
mc_lrc.tx_lrc.setTextFormat(lrcFormat);
}
delete mc_loadEvent.onEnterFrame;
//编码恢复
if (myCodePage != undefined) {
System.useCodepage = myCodePage;
} else {
System.useCodepage = false;
}
};
//
//LRC解析器
myLRC = new String();
lrcData = new Object();
lrcData.timer = new Array();
lrcData.info = new Array();
lrcData.txScroll = new Array();
function initLRC() {
i = 0;
hasMoreTags = false;
offset = 0;
for (var k = 0; k<200; k ) {
//LRC文本流分行
var cur = myLRC.indexOf("\n");
parseLineData(myLRC.slice(0, cur));
myLRC = myLRC.slice(cur 1);
if (myLRC.length<=0) {
break;
}
}
if (hasMoreTags == true) {
sortTimer();
}
trace(lrcData.timer);
startShowLRC();
}
function parseLineData(lineString) {
var lineData = new String(lineString);
//解析[00:25.62]时间标签
var startCharID = lineData.indexOf("[");
if (isNaN(lineData.slice(startCharID 1, startCharID 3)) == false && lineData.indexOf(":") == startCharID 3) {
//标准[00:25.62]格式
if (lineData.indexOf("]") == startCharID 9) {
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6)) Number(lineData.slice(startCharID 7, startCharID 9)/100);
} else if (lineData.indexOf("]") == startCharID 10) {
//兼容[00:25.625]格式
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6)) Number(lineData.slice(startCharID 7, startCharID 10)/1000);
} else if (lineData.indexOf("]") == startCharID 8) {
//兼容[00:25.6]格式
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6)) Number(lineData.slice(startCharID 7, startCharID 8)/10);
} else if (lineData.indexOf("]") == startCharID 6) {
//兼容[00:21]格式
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6));
}
} else {
var tagName;
//解析标识标签
//[ar:艺人名]
if (lineData.indexOf("[ar:") != -1) {
tagName = "艺人:";
} else if (lineData.indexOf("[ti:") != -1) {
//[ti:曲名]
tagName = "歌曲:";
} else if (lineData.indexOf("[al:") != -1) {
//[al:专辑名]
tagName = "专辑:";
} else if (lineData.indexOf("[by:") != -1) {
//[by:编辑LRC歌词的网友信息]
tagName = "歌词制作:";
function loadLRC(path) {
delete this.onEnterFrame;
lrcData.timer = new Array();
lrcData.info = new Array();
myCodePage = System.useCodepage;
System.useCodepage = true;
isLRCShow = false;
mc_lrc.tx_lrc.htmlText = " ";
mc_lrc.tx_lrc.setTextFormat(lrcFormat);
trace("LRC文档地址:" path);
lrcFile.load(path);
mc_loadEvent.onEnterFrame = function() {
if (lrcFile.getBytesLoaded()>10) {
var per = Math.floor(lrcFile.getBytesLoaded()/lrcFile.getBytesTotal()*100);
mc_lrc.tx_lrc.htmlText = "
" "正在下载歌词.." per "%";
} else {
mc_lrc.tx_lrc.htmlText = "
" "正在查找歌词.." "";
}
mc_lrc.tx_lrc.setTextFormat(lrcFormat);
};
}
//
//读取LRC文本流
lrcFile = new XML();
lrcFile.onLoad = function(success) {
if (success) {
trace(true);
myLRC = this.toString();
myLRC = myLRC.slice(myLRC.indexOf("["));
initLRC();
} else {
trace("LRC LoadError");
mc_lrc.tx_lrc.htmlText = "
" "未加载歌词" "";
mc_lrc.tx_lrc.setTextFormat(lrcFormat);
}
delete mc_loadEvent.onEnterFrame;
//编码恢复
if (myCodePage != undefined) {
System.useCodepage = myCodePage;
} else {
System.useCodepage = false;
}
};
//
//LRC解析器
myLRC = new String();
lrcData = new Object();
lrcData.timer = new Array();
lrcData.info = new Array();
lrcData.txScroll = new Array();
function initLRC() {
i = 0;
hasMoreTags = false;
offset = 0;
for (var k = 0; k<200; k ) {
//LRC文本流分行
var cur = myLRC.indexOf("\n");
parseLineData(myLRC.slice(0, cur));
myLRC = myLRC.slice(cur 1);
if (myLRC.length<=0) {
break;
}
}
if (hasMoreTags == true) {
sortTimer();
}
trace(lrcData.timer);
startShowLRC();
}
function parseLineData(lineString) {
var lineData = new String(lineString);
//解析[00:25.62]时间标签
var startCharID = lineData.indexOf("[");
if (isNaN(lineData.slice(startCharID 1, startCharID 3)) == false && lineData.indexOf(":") == startCharID 3) {
//标准[00:25.62]格式
if (lineData.indexOf("]") == startCharID 9) {
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6)) Number(lineData.slice(startCharID 7, startCharID 9)/100);
} else if (lineData.indexOf("]") == startCharID 10) {
//兼容[00:25.625]格式
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6)) Number(lineData.slice(startCharID 7, startCharID 10)/1000);
} else if (lineData.indexOf("]") == startCharID 8) {
//兼容[00:25.6]格式
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6)) Number(lineData.slice(startCharID 7, startCharID 8)/10);
} else if (lineData.indexOf("]") == startCharID 6) {
//兼容[00:21]格式
lrcData.info[i] = lineData.slice(lineData.lastIndexOf("]") 1);
lrcData.timer[i] = Number(lineData.slice(startCharID 1, startCharID 3))*60 Number(lineData.slice(startCharID 4, startCharID 6));
}
} else {
var tagName;
//解析标识标签
//[ar:艺人名]
if (lineData.indexOf("[ar:") != -1) {
tagName = "艺人:";
} else if (lineData.indexOf("[ti:") != -1) {
//[ti:曲名]
tagName = "歌曲:";
} else if (lineData.indexOf("[al:") != -1) {
//[al:专辑名]
tagName = "专辑:";
} else if (lineData.indexOf("[by:") != -1) {
//[by:编辑LRC歌词的网友信息]
tagName = "歌词制作:";
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




