Flash real-time music real frequency change (all as) is a live tour

Source: Internet
Author: User
Tags id3


Effect Display: http://k.thec.cn/liuping2006/music_jump_line/music_jump_line.swf


If you are interested, I will introduce the method of making.

The production of real-time audio beat bar
Flash's processing of sound mainly includes:
In the current version of Flash (Flash5, FLASHMX, Flash2004, Flash8), flash on the sound file processing capacity is not strong enough.
MP3 is currently the most popular voice format on the Web, because MP3 has an efficient compression (about 1/12), and can maintain the sound quality of the original voice very well.
Flash has two ways to play mp3. One is to import mp3 into flash internal (directly on the time frame, if the sound file is large, it will occupy a lot of frames; put in the library, with as binding sound), although flash can compress the mp3 again, but still make the SWF file fat The second is to place the MP3 outside of flash and use as to import the external mp3 into the SWF playback file. However, none of the above methods can display the spectral data of sound files in real time. When playing sound, if you can display the spectral characteristics of the sound in real time, like some famous media players, there are a lot of beating small pieces along with the beautiful music dancing posture, to the viewer can play a "sensual and taste" role.
Flash itself can not directly capture the spectral data in the sound file, must use other software, such as Flashamp (suitable for smaller MP3 files, flash through the array storage from the Flashamp collected MP3 spectrum data, and if the mp3 file is larger, The MP3 spectrum data collected by Flashamp will be very large. The other software SwiftMP3 the audio data from MP3 in the MP3 to SWF and represents 18 variables with variable name s0, S1, S2, S3 、......、 S17. The following data from the MP3 is stored in a SWF converted by a mp3 through SwiftMP3:
Title = "";
Artist = "";
Album = "";
ID3 = "1";
[Action in Frame 2]
[Action in Frame 3]
S0 = "1";
S1 = "11";
S2 = "4";
S3 = "3";
S4 = "2";
S5 = "6";
S6 = "2";
S7 = "3";
S8 = "4";
S9 = "3";
S10 = "2";
S11 = "2";
S12 = "1";
S13 = "2";
S14 = "1";
S15 = "1";
S16 = "1";
S17 = "1";
[Action in Frame 4]
S0 = "3";
S1 = "5";
S2 = "8";
S3 = "1";
S4 = "4";
S5 = "2";
S6 = "1";
S7 = "2";
S8 = "3";
S9 = "1";
S10 = "3";
S11 = "4";
S12 = "1";
S13 = "2";
S14 = "1";
S15 = "5";
S16 = "2";
Due to space reasons, the middle part is omitted
Telltarget ("_level0") {
Stop ();
gotoAndPlay ("");}

Therefore, you can access all the variables in the above table in Flash, such as title "title", artist "Artist", album "Album", Id3 value and variable name on each frame and its variable value (S0 = "1"; S1 = "one"; s2 = "4"; S17 = "2";). The following example shows how to access the MP3 variable to complete the production of the real-time audio beat bar in Flash
First, prepare the material
Using SWIFTMP3 to process several mp3 for SWF, this name is 1.swf, 2.swf, 3.swf 、...., and stored in a folder named Mousic_lib.
Second, the production process
① open Flash to create a new file for Music_jump_line.fla. Set this Flash file scene size to 89*70 (the purpose is to call it as a small attachment when other occasions are needed later).
② creates a name called the Music_cell movie symbol, which takes the link name in the library as Music_cell, creating 3 keyframes on Layer 1 in the Music_cell movie symbol. The purpose of storing the main code in a movie component is also to facilitate the use of this real-time audio bounce bar in other flash, just copy the past.
On the 1th keyframe, write as:
var g = 1;//defines a variable g, which is used to control the 1.swf, 2.swf, 3.swf filename of the external containing MP3 music.
On the 2nd Keyframe, write as:
Stop ();
//................. 1 ...........
var col = 0x51e450;
Bounce Block Color
var COLBT = 0xddce22;
Button color
var txtcol = 0xFFFFFF;
Progress Display Font Color
This.createemptymovieclip ("Line_cell", 1);
With (Line_cell) {
MoveTo (0, 0);
Beginfill (COL);
LineTo (4, 0);
LineTo (4, 2);
LineTo (0, 2);
Endfill ();
_visible = 0;
}
//...... 1 ... music beats small pieces
//................ 2. ...........
for (var i = 0; i<18; i++) {
Line_cell.duplicatemovieclip ("Line_cell" +i, i+20,{_x:5*i,_y:-1});
Line_cell.duplicatemovieclip ("M" +i, 40+i,{_x:5*i});
}
//...... 2. The above is the top jumping block and the jumping vertical bar.
This.createemptymovieclip ("MM", 0);
Mm.loadmovie ("mousic_lib/" +g+ ". swf");
//................. 3. ...........
Onenterframe = function () {
var mm_c = Mm._currentframe;
var mm_t = mm._totalframes;
var mm_p = Math.Round ((100*mm_c/mm_t) *100)/100;
if (mm_p<10) {
Pstext.text = "0" +mm_p+ "%";
} else {
Pstext.text = mm_p+ "%";
}
Pstext.settextformat (TF);
Text formatting should pay special attention to the text content must be placed in "Baifenbitext.settextformat (TF);" Before, otherwise the setting is invalid!!!
if (Mm._currentframe = = mm._totalframes) {
g++;
Mm.loadmovie ("mousic_lib/" +g+ ". swf");
}
if (mm. Id3 = = undefined) {
Mytext.text = "Load ...";
g = 1;
Mm.loadmovie ("mousic_lib/" +g+ ". swf");
}
for (i in mm) {
if (mm<20) {
for (var i = 0; i<18; i++) {
this["Line_cell" +i]._y =-1-mm["s" +i]*4;
this["M" +i]._yscale= Math.floor (this["Line_cell" +i]._y-this["M" +i]._y)/this["M" +i]._height) *100;
}
}
}
};
//......... 3. ...
//.................... 4. ..............
This.createemptymovieclip ("Playbtn", 6);
With (PLAYBTN) {
MoveTo (65, 4);
Beginfill (COLBT);
LineTo (73, 9);
LineTo (65, 14);
LineTo (65, 4);
Endfill ();
}
This.createemptymovieclip ("Stopbtn", 7);
With (STOPBTN) {
MoveTo (14, 4);
Beginfill (COLBT);
LineTo (24, 4);
LineTo (24, 14);
LineTo (14, 14);
LineTo (14, 4);
Endfill ();
}
Playbtn.onrelease = function () {
Delete Onenterframe;
Unloadmovie ("mm");
gotoAndPlay (3);
};
Stopbtn.onrelease = function () {
Unloadmovie ("mm");
Delete Onenterframe;
};
//....... 4. Play and stop button
//.................. 5. ...........
This.createemptymovieclip ("Nextbtn", 9);
With (NEXTBTN) {
MoveTo (80, 4);
Beginfill (COLBT);
LineTo (88, 8);
LineTo (88, 4);
LineTo (89, 4);
LineTo (89, 14);
LineTo (88, 14);
LineTo (88, 10);
LineTo (80, 14);
LineTo (80, 4);
Endfill ();
}
Nextbtn.duplicatemovieclip ("Prevbtn", 10);
Prevbtn._xscale =-100;
prevbtn._x = 89;
Nextbtn.onrelease = function () {
Delete Onenterframe;
Unloadmovie ("mm");
g++;
gotoAndPlay (3);
};
Prevbtn.onrelease = function () {
Delete Onenterframe;
Unloadmovie ("mm");
g--;
gotoAndPlay (3);
};
//...... 5. ... above for forward and back buttons
//................ 6 ..........
This.createtextfield ("Pstext", 8, 25, 2, 41, 20);
TF = new TextFormat ();
Tf.font = "Arial";
Tf.size = 10;
Tf.color = COLBT;
tf.align = "center";
//........ 6. ... above is the text that dynamically displays the progress of the playback.
This.createemptymovieclip ("Bjline",-2); //......... Background..........
With (Bjline) {
LineStyle (0, 0x1a7133, 50);
MoveTo (0, 16);
Beginfill (0x003333, 90);
LineTo (89, 16);
LineTo (89,-50);
LineTo (0,-50);
LineTo (0, 16);
Endfill ();
}
This.createemptymovieclip ("line",-1);//bounce Bar Base Horizontal
With (line) {
LineStyle (0, 0X00FF00, 50);
MoveTo (0, 0);
LineTo (89, 0);
LineTo (0, 0);
}
//............... The background "music" word ..... .................
This.createtextfield ("Sxl_text",-20, 10,-59, 70, 26);
TFS = new TextFormat ();
Tfs.font = "Arial black";
Tfs.size = 20;
Tfs.color = 0x003939;
tfs.align = "center";
Sxl_text.text = "Music";
Sxl_text.settextformat (TFS);
//...........................................................
On the 3rd Keyframe, write as:
gotoAndStop (2);
③ back to the main scene and write as: on frame 1th.
This.attachmovie ("Music_cell", "MC", 1,{_y:50});
It's done!
④ Test this music_jump_line.swf file, you can see the stage of the Green Elf Dance with the music. By following the buttons below you can control the playback and stop of the music, the previous one and the last option.
Third, the production PostScript
1. Basic technology:
①if (condition) {To execute the instruction} condition loop, if the condition is true, Flash will run the statement inside the curly braces ({}) after the condition
②with (object) {The instruction} action to be executed uses the range, the parameter evaluates the expression and the action in the object. This allows you to not have to repeat the name or path of the writing object
③for (initial value; cyclic condition; evaluated expression) {The instruction} condition loop to be executed by the loop body
④mymovieclip.createemptymovieclip (new instance name, depth) create an empty movie clip method as a child of an existing movie clip
⑤mymovieclip.createtextfield (new instance name, depth, x-coordinate, y-coordinate, text width, text height) Create a method that is a new empty text field as a child of the movie clip specified by the MovieClip parameter
⑥mymovieclip.duplicatemovieclip (new instance name, depth [, initial value]) Copy Movie clip method
⑦mymovieclip.onenterframe=function () {} event handler with constant frame-frequency refresh
⑧mymovieclip.onrelease () {} event handler function after click Release
⑨mymovieclip.attachmovie ("Link name in library", new instance name, depth [, initial value]) take a component from the library and attach it to the method in the movie specified by MovieClip on the stage
2. Key technologies:
for (i in mm) {//Traverse movie instance mm
if (mm<20) {//If the number of variables in mm is less than 20
for (var i = 0; i<18; i++) {//Because the variable s in mm has 18
this["Line_cell" +i]._y = -1-mm["s" +i]*2;/* the height variation of each runout block is affected by the corresponding numerical value in mm. The minus sign is because the registration point of each bouncing block is in the upper-left corner, so the Y-value should be negative to make it go up, *2 because it increases the amplitude of the jump and makes the movement obvious.
Externally imported 1.swf, 2.swf 、....、 n.swf. Music file contains music data its variable name is S0, S1, S2, S3 、.... S17, they have a change in the value of each frame * *
this["M" +i]._yscale= Math.floor ((this["Line_cell" +i]._y-this["M" +i]._y)/this["M" +i]._height) *100;/* The scaling of a small vertical bar in the direction of the Y axis is determined by the Y value of the bouncing small block.
}
}
}
};
3. Basic Features:
① This software plays the external music SWF file sequentially, and it automatically jumps to the first one from the beginning to the last.
②         External Music swf file can not specify the number, MUSIC_JUMP_LINE.SWF will automatically control playback.

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.