LRC lyrics synchronization

Source: Internet
Author: User
Tags regular expression split

LRC lyrics synchronization, we see the baidu Online lyrics synchronization function, now we also use flash to achieveSynchronization of lrc lyricsAndSynchronous display of lrc lyrics

You can also copy the text content, create a text document under "C: \ My Player \ LRC \", and paste the content, save the document as "blue and white porcelain. lrc ", note that the extension is". lrc ".

II. LRC content analysis
The preparation is complete. Analyze the LRC file below. It is called LRC because it is short for Lyric. This format is clear at a glance. The numbers in the previous "[]" indicate the start time of the subsequent lyrics. For example. 25] The scene of colored white flowers has jumped to the bottom of the bowl. "It means that at 1 minute and 50.25 seconds, the lyrics are" the scene of colored white flowers has jumped to the bottom of the Bowl ".
Another form is. 92] [02: 25. 63] [00: 56. 90] The day is waiting for smoke and rain. "This form is often used in the authorization part (commonly known as the climax part of the song), which is expressed. 92. 63, 00: 56. the lyrics of the 90 s are "The sky is waiting for smoke and rain ". Due to the existence of this form, the subsequent programming is a little complicated, but it doesn't matter. It's okay to rely on your smart wisdom.

3. Prerequisites
1. in ActionScript 3, Unicode is used by default to decode external files. If the read text is not Unicode encoded, it is written according to the operating system code page, such as GB2312, you must first import flash. system. system class. set useCodePage to true, which is false by default. That is, operating system page decoding is not used by default.
If System. useCodePage = false and the external LRC file encoding format is ANSI, the Chinese lyrics are garbled. There are two solutions: one is to change the external LRC file encoding format to Unicode; the other is to add a System statement to the document class without changing the external file encoding format. useCodePage = true. Since the latter method is easy to use, we adopt the second method.

2. Read sound:
Var sound: Sound = new Sound ();
Sound. load (new URLRequest ("Music/Qinghua porcelain "));

3. Play the sound and obtain the current playback time (MS ):
Var SC: SoundChannel;
Var sound: Sound = new Sound ();
Sound. load (new URLRequest ("Music/Qinghua porcelain "));
SC = sound. play ();
Stage. addEventListener (Event. ENTER_FRAME, EnterFrame );
Function EnterFrame (evt: Event): void {
Trace (SC. position );
  }
Here we declare SC as a global variable (or class variable) because it is used in multiple methods.

4. Read external files:
Var loader: URLLoader = new URLLoader ();
Loader. load (new URLRequest ("LRC/blue/white porcelain. lrc "));
Loader. addEventListener (Event. COMPLETE, LoadFinish );
Function LoadFinish (evt: Event): void {
Trace(evt.tar get. data );
  }

5. Separate strings into arrays (String. split) by separators ):
Var str: String = "FL Basic Theory Master ";
Var array: Array = str. split ("");
Trace (array );
// Output array: [[FL], [Basic], [Theory], [Master]
Str = "http://111cn.net ";
Array = str. split (".");
Trace (array );
// Output array: [[http: // blog], [sina, com], [cn/yyy98]

6. Simple regular expression application:
1> get matching times:
Var Pattern: RegExp =/Window/g;
// All strings named "Window"
Var str: String = "Windows seems like a Window, so called Windows OS! ";
Trace (str. match (Pattern). length)
// Result: 3
2> get the correct match:
Var foo: regExp =/[0-3] [0-9] \/[0-1] [0-9] \/[0-2] [0-9] [0-9- 9] [0-9]/g;
// Indicates all strings in the format of "day/month/year"
Var str: String = "Date Format: 2006/12/25 2006-12-25 12/25/2007 25/12/2007"
Trace (str. match (foo ))
// Result: 25/12/2007

7. String substring operation (String. substr ):
Var str: String = "[. 92] [. 63] [. 90] The weather is waiting for smoke and rain ";
Trace (str. substr (0, 30 ));
// Starts from index 0 and takes 30 characters
// Result: [. 92] [. 63] [. 90]
Trace (str. substr (30 ));
// Write only one parameter to indicate the end position from the index to the string.
// Result: the weather is waiting for the rain

8. Application of comparison functions in array sorting:
Var a: Object = {price: 20, number: 3 };
Var B: Object = {price: 10, number: 7 };
Var c: Object = {price: 50, number: 1 };
Var amountAry: Array = [a, B, c];
Function compare (paraA: Object, paraB: Object): int {
Var resultA = paraA. price * paraA. number;
Var resultB = paraB. price * paraB. number;
If (resultA> resultB) return 1;
If (resultA <resultB) return-1;
Return 0;
  }
AmountAry. sort (compare );
Trace (amountAry [0]. price); // output: 50
Trace (amountAry [1]. price); // output: 20
Trace (amountAry [2]. price); // output: 10

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.