I wrote it for one day and completed the class for C # To operate the lyrics. There are explanations in the specific usage, but they are not perfect because there is no perfect thing. If you feel betterLeave a message for me.! Thank you very much. I am not a newbie ....
The class of the lyrics. I have not changed the namespace.
Using system; <br/> using system. collections. generic; <br/> using system. text; <br/> using system. io; <br/> using system. windows. forms; </P> <p> namespace windowsapplication1 <br/> {<br/> class lyrics <br/> {<br/> public struct TLRC <br/> {<br/> Public int MS; // millisecond <br/> Public String LRC; // corresponding lyrics <br/>}</P> <p> // <summary> <br/> // a standard array of lyrics <br/>/ /// </Summary> <br/> Public TLRC [] TLRC; <br/> // <summary> <br/> // enter the path of the lyrics file to process the lyrics. <br/> /// </Summary> <br/>/ // <Param name = "file"> </param> <br/> Public lyrics (string file) <br/>{< br/> streamreader sr = new streamreader (getlrcfile (file), encoding. default); <br/> string [] lrc_1 = sr. readtoend (). split (New char [] {'[', ']'}); <br/> Sr. close (); </P> <p> format_1 (lrc_1); <br/> format_2 (lrc_1); <br/> format_3 (); <br/>}< br/> /// <summary> <br/> // format the same character at different times, for example. 52] [00: 34. 53] [00: 34. 54] Because I have no strength "<br/> /// </Summary> <br/> // <Param name =" lrc_1 "> </param> <br /> private void format_1 (string [] lrc_1) <br/> {<br/> for (INT I = 2, j = 0; I <lrc_1.length; I + = 2, j = I) <br/>{< br/> while (lrc_1 [J] = string. empty) <br/>{< br/> lrc_1 [I] = lrc_1 [J + = 2]; <br/>}< br/> // <summary> <br/> // Add data to the struct <br/> /// </Summary> <br/> /// <Param name = "lrc_1"> </param> <br/> private void format_2 (string [] lrc_1) <br/>{< br/> TLRC = new TLRC [lrc_1.length/2]; <br/> for (INT I = 1, j = 0; I <lrc_1.length; I ++, J ++) <br/>{< br/> TLRC [J]. ms = timetoms (lrc_1 [I]); <br/> TLRC [J]. LRC = lrc_1 [++ I]; <br/>}< br/> // <summary> <br/> // time format. 61 "millisecond conversion <br/> // </Summary> <br/> // <Param name =" lrc_t "> </param> <br/> // /<returns> </returns> <br/> private int timetoms (string lrc_t) <br/>{< br/> float M, S, MS; <br/> string [] lrc_t_1 = lrc_t.split (':'); <br/> // tryparse cannot be used here, for example, "by: 253057646". <br/> try <br/>{< br/> M = float. parse (lrc_t_1 [0]); <br/>}< br/> catch <br/>{< br/> return 0; <br/>}< br/> float. tryparse (lrc_t_1 [1], out S); <br/> MS = m * 60000 + S * 1000; <br/> return (INT) MS; <br/>}< br/> /// <summary> <br/> // sort, chronological order <br/> /// </Summary> <br/> private void format_3 () <br/>{< br/> TLRC tlc_tlc_temp; <br/> bool B = true; <br/> for (INT I = 0; I <TLRC. length-1; I ++, B = true) <br/>{< br/> for (Int J = 0; j <TLRC. length-I-1; j ++) <br/>{< br/> If (TLRC [J]. ms> TLRC [J + 1]. ms) <br/>{< br/> tlc_temp = TLRC [J]; <br/> TLRC [J] = TLRC [J + 1]; <br/> TLRC [J + 1] = tlc_temp; <br/> B = false; <br/>}< br/> If (B) break; <br/>}</P> <p> Public int mark; <br/> /// <summary> <br/> // read the next record, next record <br/> /// </Summary> <br/> /// <returns> </returns> <br/> Public String Readline () <br/>{< br/> If (Mark <TLRC. length) <br/>{< br/> return TLRC [Mark ++]. LRC; <br/>}< br/> else <br/>{< br/> return NULL; <br/>}</P> <p >}< br/> // <summary> <br/> // time when the lyrics of the current row are read <br/> /// </Summary> <br/> /// <returns> </returns> <br/> Public int currenttime <br/>{< br/> Get <BR/>{< br/> If (Mark <TLRC. length) <br/>{< br/> return TLRC [Mark]. ms; <br/>}< br/> else <br/>{< br/> return-1; <br/>}</P> <p> // <summary> <br/> // obtain the LRC lyrics file (current Directory) <br/> // </Summary> <br/> // <Param name = "file"> </param> <br/> // <returns> </returns> <br/> private string getlrcfile (string file) <br/> {<br/> return path. getdirectoryname (File) + "//" + path. getfilenamewithoutextension (File) + ". LRC "; <br/>}< br/>
It is easy to operate. 2011-05-06
Author: Weiwei (Yinhe yuanmu)