On dynamic Lyrics-lyrics display

Source: Internet
Author: User

1 Introduction

After analysis, generation and parsing, I believe we are no longer unfamiliar with the dynamic lyrics, now the most important thing is, how to display the dynamic lyrics, here is no longer the introduction of Java Swing above how to display, because in the generation of the article, has done some simple introduction, This article focuses on how dynamic lyrics appear on Android.

2 Display

About the smooth scrolling of the lyrics, has always been using Android scroller to scroll, found in the lyrics sliding fast forward, has been unable to achieve, limited capacity. Fortunately, found a post, this post is really a great help, here first posted, his blog, I strongly recommend you look at his blog, he said more detailed clear, I here simply say:

Custom view with a strong attack, using a custom view to implement a custom Lyricview implementation of the next chapter of the lyrics display control

Here, I refer to his blog and code, to his own music player has been reorganized, on its basis to achieve smooth movement of lyrics and fast sliding.

Here's what I realized



2.1 Dynamic Lyrics API

From the figure, graphics2d in the painting text, first draw the default color of the lyrics text, and then set the length of the clip layer width, and then paint the "highlight" lyrics text, as long as we constantly modify the width of the clip layer, we want the dynamic lyrics effect.

Part of the code:


2.2 Dynamic Lyrics Display principle

1. Get the row index (LINDEX) where the current lyrics are located by the current playback time

2. Get the lyrics of the current line through the row index (LINDEX) lyricslineinfo

3. Gets the "word" index of the current line playback, the "word" duration t, through the current row index (LINDEX) and the current time

4. Obtain the width S of the lyrics "word" by paint and calculate the average speed: V = s/t

5. Gets the time that has been played during the "word" duration for the current time: T1

6. Calculate the length of the clip layer L = V * T1

Some of the code is as follows:

Get the progress of the play in the word


Get the length that has been played


2.3 Lyrics Move gently

1. Customize view and use Valueanimator animations to achieve smooth motion of each line of lyrics

2. Move distance offsety= New line number * (font height + empty line height)-old line number * (font height + empty line height), personal feeling this is more important, because this sentence, the movement of the shift and the line number of the lyrics together, for the back of the rapid sliding lyrics and determine the position of the lyrics after sliding, provide the conditions.

3. In order to let the lyrics center display, so in the painting lyrics, the center of the lyrics to subtract offsety size.

Some of the code is as follows:



2.4 Lyrics Fast Forward

Override the Ontouchevent event, used in combination with the Velocitytracker class and Valueanimator, to calculate the speed of the gesture, and then calculate the position of the lyrics scrolling based on the gesture speed.

2.5 Lyrics line break

Here, I realized the way is relatively simple, is to parse from the lyrics files from the lyrics collection, according to the current view size and font size, to reorganize, to get a new lyrics collection, so as to ensure that the lyrics can not change the implementation of the idea, to achieve the lyrics of the line, but this method of the requirements of the lyrics is relatively high, It is the lyrics file to be accurate to the "word", this line of lyrics because the font size is separated into two lines of lyrics, because each "word" has a continuous time, it is easy to generate a new line of lyrics.

Some of the code is as follows:



2.6 Lyrics Font Scaling

As long as the current scroll position offsety is set to the current line, and then modify the font size, and then re-painting the view, you can.

Some of the code is as follows:


3 references

Custom view with a strong attack, using a custom view to implement a custom Lyricview implementation of the next chapter of the lyrics display control

Karaoke Lyrics Implementation Mode

4 source Code

Lele Music-android Version

5 Last

I hope the lyrics analysis, generation, parsing and display are helpful to some readers who want to understand the dynamic lyrics. If there is infringement, please inform.

Finally, there is no last.

Talking about dynamic Lyrics-lyrics display 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.