More complete Android MP3 LRC lyrics scrolling highlighting (with source code) _android

Source: Internet
Author: User

1. Previous scrolling just Anch to refresh, now is not by line to scroll, in fact, is in a certain period of time to move the whole, for example, in the 1S refresh 10 times, because the naked eye looks like scrolling.

The key code is as follows:

Copy Code code as follows:

Float plus = Currentdunringtime = 0? 30
: 30
+ (((float) currenttime-(float) sentencttime)/(float) currentdunringtime)
* (float) 30;
Scroll up this is based on the length of the lyrics to scroll, the overall move up
Canvas.translate (0,-plus);

Plus is the size of each move, which is calculated according to the duration of the lyrics, and the longer the time, the smaller the plus value. Specific look at the code.

Here is the message to get the lyrics:

Copy Code code as follows:

public void Updateindex (long) {
This.currenttime = time;
Lyrics serial Number
index = Mlyric.getnowsentenceindex (time);
if (index!=-1) {
Sentence sen = sentencelist.get (index);
Sentencttime = Sen.getfromtime ();
Currentdunringtime = Sen.getduring ();
}
}

Here's the new thread:
Copy Code code as follows:

Class Uiupdatethread implements Runnable {
long time = 100; Scrolling speed
public void Run () {
while (Mp.isplaying ()) {
Lyricview.updateindex (Mp.getcurrentposition ());
Mhandler.post (Mupdateresults);
try {
Thread.Sleep (time);
catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}
}

Project Link: Click to download

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.