Tutorial 2 of MP3 player: lyrics synchronization

Source: Internet
Author: User

The LRC lyrics in the MP3 player were analyzed last time. Today we will talk about how to play the LRC lyrics in sync with those in the mp3 player.

In as2, we generally use the sound or MediaPlayback component for playing mp3 files... the former is the sound management class, and the latter supports playing mp3 and flv files ..

For mp3 players .. we can directly use sound to solve basic requirements. However, to better synchronize LRC synchronization, we will use the MediaPlayback component, because MediaPlayback provides the cuePoint (prompt point) function, we can add the time in the array of lyrics to MediaPlayback. In this way, we can listen to the cuePoint event of MediaPlayback through the middleware to achieve synchronous display.

First, we pull a MediaPlayback component to the library ..

Then add the lyrics as the prompt point.
_ Root. attachMovie ("MediaPlayback", "mp3Player", 0); // Use the code to copy the component.
Then we use the addCuePoint function in MediaPlayback to add the lrc array as the cuepoint
Format: mp3Player. addCuePoint ("lyrics", Time );

Add a cuepoint event to display the lyrics.
Var listenerObject: Object = new Object ();
ListenerObject. cuePoint = function (eventObj: Object ){
TxtLRC. text = eventObj. cuePointName; // here... the lyrics are the cuepoint attribute of the prompt point.
};
Mp3Player. addEventListener ("cuePoint", listenerObject );

Now, you only need to specify the address of the lyrics and the address of the mp3.

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.