AS3 music player with control playback progress

Source: Internet
Author: User

Click the progress bar to start playing the music from the mouse click

Production process:
1, create a new flash CS3 document, save the name "Control playback Progress", stored in the music folder. Set document size: 252x114 pixels, Frame frequency: 24fps.
2. The first layer is called "Player background", and a player background is drawn on the layer.

3, new layer, called "Play Progress Box", draw a borderless rectangle, corner radius of 8, Width 202 high 6, fill color for #006600, so that its vertical level on the stage.

4, new layer, called "Play Progress Background", draw a borderless rectangle, corner radius of 8, Width 200 high 4, from top to bottom fill #99cc00 to #55802b gradient, so that its vertical level on the stage.

5, new layer, called "Play progress Bar", draw a borderless corner rectangle, corner radius of 0, Width 202 high 6, from top to bottom fill #00ccff to #0066ff gradient, so that its vertical level on the stage, converted to a movie clip named "Play Progress bar." The instance in the scene is named "Bfjdt_mc".

6, new layer, called "Play progress Bar Mask", the "Play Progress Background" layer frame copy and paste on the "Play Progress bar Mask" layer, right-click Select "Mask layer."
7, create a new layer, called "Progress Control", draw a borderless rectangle of rounded corners, corner radius of 0, Width 200 high 6, fill the color arbitrary, so that its vertical level on the stage, converted to "Progress control" button symbol, and the "bouncing" frame on the "click" Frame. The instance in the scene is named "Jdcz_btn".

8, the new layer, called "as", write the following code on the frame:
declaring variables
The code is as follows Copy Code
var _sound:sound=new sound ();
var _channel:soundchannel=new soundchannel ();
var loaded:int;
var total:int;
var _length:int;
var position:int;
var Hcbfb:number;
var Bfjdbfb:number;
Load MP3 and Play
Varurl:string= "****.mp3";/The MP3 music file name on your computer and put the file in a folder with the MP3 music file.
var _request:urlrequest = new URLRequest (URL);
_sound.load (_request);
_channel=_sound.play ();
Bfjdt_mc.visible=false;
Add constant Update Listener events
AddEventListener (EVENT.ENTER_FRAME,YX);
function Yx (event:event): void {
loaded=_sound.bytesloaded;
Total=_sound.bytestotal;
_length=_sound.length;
Position=_channel.position;
Hcbfb=loaded/total;
_LENGTH/=HCBFB;
Bfjdbfb=position/_length;
BFJDT_MC.SCALEX=BFJDBFB;
Bfjdt_mc.visible=true;
}
if (hcbfb>=1) {
Jdcz_btn.addeventlistener (MOUSEEVENT.CLICK,JDCZ);
}
}
Playback Progress Control
function Jdcz (e:mouseevent): void {
_channel.stop ();
var bfjdbfb:number= (mouseX-26)/200;
BFJDT_MC.SCALEX=BFJDBFB;
Position =_LENGTH*BFJDBFB;
_channel=_sound.play (position);
}
You can also add a drag button to control progress
The 7th step should read:
Create a new layer named "Progress Slider", Draw a round button, 14 height 14 wide, and fill your favorite color. Convert to a movie clip named Volume slider (the registration point is in the center). The instance in the scene is named "Jdhk_btn", coordinates x:26, y:57.

Write the following code on the frame of the as layer:
The code is as follows Copy Code
DECLARE variable var _sound:sound=new sound ();
var _channel:soundchannel=new soundchannel ();
var loaded:int;
var total:int;
var _length:int;
var position:int;
var Hcbfb:number;
var Bfjdbfb:number;
var tdfw:rectangle=new Rectangle (26,57,200,0)
var tdzj:boolean=false
Load MP3 and Play
Varurl:string= "****.mp3";/The MP3 music file name on your computer and put the file in a folder with the MP3 music file.
var _request:urlrequest = new URLRequest (URL);
_sound.load (_request);
_channel=_sound.play ();
Bfjdt_mc.visible=false;
AddEventListener (EVENT.ENTER_FRAME,YX);
function Yx (event:event): void {
loaded=_sound.bytesloaded;
Total=_sound.bytestotal;
_length=_sound.length;
Hcbfb=loaded/total;
Bfjdt_mc.visible=true;
if (Tdzj==false) {
Position=_channel.position;
Bfjdbfb=position/_length;
BFJDT_MC.SCALEX=BFJDBFB;
jdhk_btn.x=26+bfjdbfb*200;
} else {
bfjdbfb= (JDHK_BTN.X-26)/200;
BFJDT_MC.SCALEX=BFJDBFB;
Position =_LENGTH*BFJDBFB;
}
}
Progress Slider Drag
Jdhk_btn.buttonmode=true;
Jdhk_btn.addeventlistener (MOUSEEVENT.MOUSE_DOWN,TD);
Function TD (E:mouseevent): void {
Tdzj=true;
Jdhk_btn.startdrag (FALSE,TDFW);
Stage.addeventlistener (MOUSEEVENT.MOUSE_UP,SF);
* * If this listener event is not placed here, you use the mouse to click anywhere on the stage and then release the mouse,
Music also pauses during normal playback. */
}
Jdhk_btn.addeventlistener (MOUSEEVENT.MOUSE_UP,SF);
function SF (e:mouseevent): void {
Stage.removeeventlistener (MOUSEEVENT.MOUSE_UP,SF);
Tdzj=false;
Stopdrag ();
_channel.stop ();
_channel=_sound.play (position);
}

Flash source Download Address

http://www.111cn.net/down/2010 Music Player (1)--Playback Progress 1.swf
http://www.111cn.net/down/2010 Music Player (1)--Playback Progress 2.swf

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.