Flash Display LRC Lyrics principle

Source: Internet
Author: User
Tags array sort sort tagname
Show ttp://www.flashk.org/.....sukii-o/mp3/
S2 Music Player supports LRC lyrics display, it's got the address:
http://www.flashk.org/.....Sukii-o/mp3/
ZAs developed by S2 Music player LRC Lyrics principle (provided by ZAs):
--Interface--
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 File Address:" +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 = "


"+" is downloading lyrics ... " +per+ "%";
} else {
Mc_lrc.tx_lrc.htmlText = "


"+" is looking for lyrics ... " +"";
}
Mc_lrc.tx_lrc.setTextFormat (Lrcformat);
};
}
//
Read LRC text stream
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 = "


"+" does not load the lyrics "+";
Mc_lrc.tx_lrc.setTextFormat (Lrcformat);
}
Delete Mc_loadevent.onenterframe;
Code Recovery
if (mycodepage!= undefined) {
System.usecodepage = Mycodepage;
} else {
System.usecodepage = false;
}
};
//
LRC Parser
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 Text Stream Branch
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);
Parse [00:25.62] Time label
var Startcharid = Linedata.indexof ("[");
if (Linedata.slice (startcharid+1, startcharid+3)) = = False && linedata.indexof (":") = = startcharid+3) {isNaN
Standard [00:25.62] format
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) {
compatible [00:25.625] format
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) {
compatible [00:25.6] format
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) {
compatible [00:21] format
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;
Resolving identity Labels
[ar: Artist name]
if (Linedata.indexof ("[ar:")!=-1) {
TagName = "Entertainer:";
else if (Linedata.indexof ("[Ti:")!=-1) {
[Ti: Qu name]
TagName = "Song:";
else if (Linedata.indexof ("[Al:")!=-1) {
[Al: Album Name]
TagName = "album:";
else if (Linedata.indexof ("[By:")!=-1) {
[By: Edit LRC Lyrics of the user information]
TagName = "lyrics making:";
}
if (Linedata.lastindexof ("]") >linedata.lastindexof ("[")) {
Lrcdata.info[i] = Tagname+linedata.slice (Linedata.lastindexof (":") +1, Linedata.lastindexof ("]"));
} else {
Lrcdata.info[i] = Linedata;
}
if (Linedata.indexof ("[Offset:")!=-1) {
[Offset: Time-compensated value]
Lrcdata.info[i] = "------------------------------------------";
offset = number (Linedata.slice (Linedata.lastindexof (":") +1, Linedata.lastindexof ("]")));
if (isNaN (offset)) {
offset = 0;
}
}
Lrcdata.timer[i] = 0;
}
i++;
[01:17][02:24][02:53][03:21] Multi-time label support
var surplusdata = new String (Linedata.slice (Linedata.indexof ("]) +1));
if (Surplusdata.indexof ("[")!=-1) {
Hasmoretags = true;
Parselinedata (Surplusdata);
}
}
function Sorttimer () {
Lrcdata.timerid = new Array ();
for (var i = 0; I lrcdata.timerid[i] = i;
}
Use Quick sort (standby)
Quicksorter (Lrcdata.timer);
Insertionsorter (Lrcdata.timer);
Lrcdata.tmpinfo = new Array ();
for (var i = 0; I lrcdata.tmpinfo[i] = lrcdata.info[lrcdata.timerid[i]];
}
Lrcdata.info = Lrcdata.tmpinfo;
}
Array Sort algorithm: Insert sort
The core of the algorithm code was found on the Internet.
function Insertionsorter (list) {
for (var i = 1; I var t = list[i];
var j = i;
while ((j>0) && (list[j-1]>t)) {
LIST[J] = list[j-1];
var MyC = lrcdata.timerid[j];
LRCDATA.TIMERID[J] = lrcdata.timerid[j-1];
Lrcdata.timerid[j-1] = MyC;
--j;
}
LIST[J] = t;
}
}
Quick Sort (standby)
The core of the algorithm code was found on the Internet.
function Quicksorter (list) {
var low = 0;
var high = list.length-1;
if (High<=low) {
Return
else if (high = = low+1) {
if (List[low]>list[high]) {
Swap (Low, high);
Return
}
}
Myquicksort (list, low, high);
}
function Myquicksort (list, low, high) {
if (low var pivot = Partition (list, low, high);
Myquicksort (list, low, pivot-1);
Myquicksort (list, pivot+1, high);
}
}
function Partition (list, low, high) {
var pivot;
var pivot = List[low];
while (Low=pivot) {
high--;
}
if (low!= high) {
Swap (Low, high);
low++;
}
while (Low low++;
}
if (low!= high) {
Swap (Low, high);
high--;
}
}
return to Low;
}
function Swap (l, R) {
var myl = lrcdata.timerid[l];
LRCDATA.TIMERID[L] = Lrcdata.timerid[r];
Lrcdata.timerid[r] = myl;
LRCDATA.TIMER[L] = lrcdata.timer[l] ^ lrcdata.timer[r];
LRCDATA.TIMER[R] = lrcdata.timer[l] ^ lrcdata.timer[r];
LRCDATA.TIMER[L] = lrcdata.timer[l] ^ lrcdata.timer[r];
}
//
LRC Display
function STARTSHOWLRC () {
This.onenterframe = Chectimer;
Islrcshow = true;
var t = Gettimer ();
var mytexttest = "";
for (var i = 0; i<=lrcdata.info.length; i++) {
Mytexttest + = lrcdata.info[i]+ "\ n";
Mc_lrc.tx_lrc.text = Mytexttest;
Lrcdata.txscroll[i] = Mc_lrc.tx_lrc.maxscroll;
}
Trace (Gettimer ()-T);
Trace (Lrcdata.txscroll);
Mc_lrc.tx_lrc.htmlText = "";
Showlrcinfo (0);
}
t = 0;
function Chectimer () {
if (_root.musicplay.mysound.position-checbackposition<-500) {
t = 0;
Mc_lrc.tx_lrc.scroll = 0;
}
Checbackposition = _root.musicplay.mysound.position;
Time detection
if (_root.musicplay.mysound.position>lrcdata.timer[t]*1000-600-offset && lrcdata.timer[t]>= Lrcdata.timer[t-1]) {
if (Lrcdata.timer[t]!= 0) {
Mc_lrc.tx_lrc.scroll = lrcdata.txscroll[t-1]+3;
}
gotoAndPlay (8);
n = t;
t++;
}
}
FontColor1 = new String ("005cb9");
FontColor2 = new String ("FFFFFF");
Lrcformat = new TextFormat ();
lrcformat.align = "center";
function Showlrcinfo (ID) {
Frontinfo = new String ();
for (var i = 0; I frontinfo + = lrcdata.info[i]+ "
";
}
Backinfo = new String ();
for (var i = id+1 i<=lrcdata.info.length; i++) {
Backinfo + = lrcdata.info[i]+ "
";
}
Mc_lrc.tx_lrc.htmlText = "" +frontinfo+ "" + "" +lrcdata.info[id]+ "
"+" "+backinfo+";
Mc_lrc.tx_lrc.setTextFormat (Lrcformat);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.