Flash production LRC Lyrics player tutorial

Source: Internet
Author: User
Tags new features requires tostring
The tutorial since Winamp out a mini lyrics, the author has been in the heart itch, want to find a time to do one myself.
Now do it, everybody preview the effect first.
Test address A
asp5.6to23.com/7years/yiyuan7years/hbro/player/mp3player_x1.swf
Test Address Two
download.incoo.com/blueidea/hbro/player/mp3player_x1.swf
The lyrics are now standard Winamp's LRC files, downloaded from elsewhere, without any modifications,
That is, this player can be used to play the LRC file in Winamp format.
New features of the player: click on the lyrics to let the song jump to the appropriate location
A small bug: Because of the use of sound flow loading, so slow speed, the playback is not very smooth.
Then I will write a tutorial, first to introduce you to the main use of as technology:
1 tostring method with XML object
2 common processing methods for arrays.
3 A small number of string functions.
4 properties and events for sound objects.
The author will be in the next time the specific production method
The player is divided into three parts:
1 playlist for recording music file paths
2 control area to control music file playback
3 lyrics player showing lyrics
The first two parts are the classic MP3 player. And I have to admit that I did not do as others, coupled with the relevant tutorials are also very easy to find, so here only to introduce the production of the lyrics broadcast part.
Because the lyrics are synchronized with the music, so making the player requires three types of files:
1SWF format player That's what we're going to do
2 Music file MP3, I believe we can download it
3 Lyrics File LRC, is the Winamp format lyrics file, you can go to the Winamp homepage download, you can also go to the following site:
www.rixiu.com/
The file is ready and the next step is to put the file in the right place.
Create a new folder on your local hard disk player, set up two folders in the Sound,lyrics, and Flash document PLAYER.FLA.Sound folder put 1.mp3,lyrics into file 1.LRC
Start the Flash file below:
Open the flash that you just created, at the home view first frame input as:
var song=new Sound ();//create object to load sound
Song.loadsound ("Sound/1.mp3", true)//reads the sound file as a stream of data. If you want an event sound, change the true to false;
Song.start (0,1)/play sound from the beginning, Cycle 1 times. The above is the code that loads the MP3 file, which is synchronized with the LRC file that is loaded below.
The sound file requires a sound object as a container, and the lyrics file also requires a container. But Flash does not have a built-in lyric object, so it is necessary to create it yourself.
In the preview, the list box that shows the lyrics is the container for the LRC file. The following starts the creation.
Create an MC in the home scene, named Lyricsitems, with the same instance name.
Once you have created this container, you can use it to read the LRC file.
So, while the sound is loading, we can use it to read the lyrics file.
In the first frame add as:
Song.onload=function () {
Lyricsitems.loadlyrics ("LYRICS/1.LRC")//The function will be defined in Lyricsitems.
Enter the editing area of the Lyricsitems.
In the first frame enter as:
function (filepath) {
This defines the function to read the lyrics.
First, let LRC file read into Flash.
Perhaps everyone will find it strange that flash can read LRC files?
You may want to start with Notepad to open the LRC file, found that it is actually a text document.
For text documents, the XML object of Flash can be read.
The author once read a wrong XML file with an XML object and found that many of the methods of the XML object failed to invoke, but the ToString method was able to return the same string as the contents of the text document (only some of the HTML characters escaped), that is to say, Using XML objects, you can read all the LRC files into Flash.
Add the following code to the Loadlyrics function:
var lyrics=new XML ()
Lyrics.load ("LYRICS/1.LRC")
Lyrics.onload=function () {
Lyricsstring=lyrics.tostring ()
Trace (lyricsstring)
To test the movie, you will find that the entire text document is read into the lyricsstring.
Here's how to analyze the structure of the LRC file and extract the information we need from the inside.

Standard Lyrics File Example:
[TI: Black humor]
[AR: Jay Chou]
[Al:jap]
[By: Lyrics My Love http://www.51lrc.com]
[offset:400]
[00:02.00] Word/song: Jay Chou
[00:05.49] Lyrics My Love
[00:09.48]http://www.51lrc.com
[00:15.84] sad because of the stuffy for a long time
[00:21.18] because of thinking too much
[00:24.91] is psychological played a role
[00:30.89] You say a wry smile is always with you
[00:36.13] A little reluctant to be together
[00:39.83] It's time for me to take my leave
[02:45.62] [00:44.86] don't want too much
[02:47.71] [00:47.41] I guess I heard the wrong mistake.
[02:53.55] [00:53.28] Please, I think there's something wrong with your head.
[03:00.53] [01:00.11] say it casually.
[03:04.49] [01:02.47] In fact, I have already read through not to say more
[03:12.19] [01:09.94] But I'm afraid that tears won't hold
[03:16.31] [01:15.77] Don't know your black humor
[03:23.51] [01:23.25] figured it out again
[03:30.61] [01:30.63] Have you thought about it for a long time?
[03:37.92] [01:37.72] I don't want to expose you
[03:46.16] [01:45.85] As a joke to you
[03:53.54] [01:53.22] figured it out again
[04:16.74] [04:01.06] [02:00.76] Have you thought about it for a long time?
[04:23.15] My serious defeat to black humor
Structure Analysis:
1 file header is the text that records lyrics information
Here is the message of time and lyrics.
2 Each row is made up of one or several time values marked with brackets and the lyrics to be displayed for that time.
Such as:
[04:07.94] [02:07.79] to your black humor
The words "Lose your black humor" are shown in 2 minutes, 7 seconds, 79 and 4 minutes, 7 seconds, 94.

Once you understand the structure of the LRC file, you can use as powerful string processing to extract some of the values contained in it.

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.