Android lyrics synchronization implementation

Source: Internet
Author: User
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
  • Related Article

    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.