I believe many of my friends have made Android music players, but will it be monotonous to play songs? Many of my friends have thought about synchronizing the lyrics, so I will share my personal experience with you;
In fact, the process of synchronizing the lyrics is very simple:
1. parse the LRC lyrics File
2. LRC lyrics display
3. Synchronization of lyrics and playing music
1. Read the lyrics file:
/**
* Reading files
**/
Public String read (string path ){
Treemap Lrc_read = new treemap ();
String data = "";
Try {
File SaveFile = new file (PATH );
Fileinputstream stream = new fileinputstream (SaveFile );
Bufferedreader BR = new bufferedreader (New inputstreamreader (
Stream, "gb2312 "));
Int I = 0;
While (Data = Br. Readline ())! = NULL ){
Data = data. Replace ("[","");
Data = data. Replace ("]", "@");
String splistdata [] = data. Split ("@");
String lrccontenet = splistdata [splistdata. Length-1];
For (Int J = 0; j iterator = lrc_read.keyset (). iterator ();
Lrcobject oldval = NULL;
Int I = 0;
Stringbuffer sb = new stringbuffer ();
While (iterator. hasnext ()){
Object Ob = iterator. Next ();
Lrcobject val = (lrcobject) lrc_read.get (OB );
If (oldval = NULL)
Oldval = val;
Else {
Lrcobject Item1 = new lrcobject ();
Item1 = oldval;
Item1.timeline = Val. begintime-oldval. begintime;
Lrc_map.put (New INTEGER (I), Item1 );
SB. append (string. Format ("[% 04d]-[% 04d]-% s/n", item1.begintime,
Item1.timeline, item1.lrc ));
I ++;
Oldval = val;
}
}
Data = sb. tostring ();
String da = data;
Return data;
}
/**
* It is impossible to find the subscript of the sentence currently being played. Because you must add your own sentence at the beginning, you cannot find it after adding it.
*
* @ Return subscript
*/
Private int getnowsentenceindex (long T ){
For (INT I = 0; I
Previous: asynctask
Next article: Android reads and writes TXT text files