SoFunction
Updated on 2025-04-10

More complete android MP3 LRC lyrics scroll highlighting (with source code)

1. In the past, the scrolling was just to refresh the line, but now it is not to scroll according to the line. In fact, it is to move upwards as a whole within a certain period of time. For example, refreshing 10 times in 1S, because it recognizes that the naked eye looks like it is scrolling.

The key code is as follows:

Copy the codeThe code is as follows:

        float plus = currentDunringTime == 0 ? 30
                : 30
                        + (((float) currentTime - (float) sentenctTime) / (float) currentDunringTime)
                        * (float) 30;
// Scroll up This scrolls according to the length of the lyrics and moves upward as a whole
        (0, -plus);

plus is the size of each move, which is calculated based on the time the lyrics last. The longer the time, the smaller the value of plus is. It depends on the code specifically.

Here is the information for obtaining the lyrics:

Copy the codeThe code is as follows:

 public void updateIndex(long time) {
   = time;
// Lyrics
  index = (time);
  if (index != -1) {
   Sentence sen = (index);
   sentenctTime = ();
   currentDunringTime = ();
  }
 }

The following is the new thread:
Copy the codeThe code is as follows:

 class UIUpdateThread implements Runnable {
long time = 100; // scrolling speed
  public void run() {
   while (()) {
    (());
    (mUpdateResults);
    try {
     (time);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     ();
    }
   }
  }
 }

Project link:Click to download