2016-10-13 00:16:48 点击量:8 标签: 收藏本文
[AS3]mp3音乐播放器实例源代码参考,mp3音乐播放器,音乐播放器
- package {
- import flash.display.SimpleButton;
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.media.SoundTransform;
- import flash.display.Stage;
- import flash.net.URLRequest;
- import flash.geom.Rectangle;
- import flash.display.DisplayObject;
- public class DocumentClass extends MovieClip{
- var mp3Url:String="http://localhost/UserVideo/2007108/aaa.mp3";
- var _sound:Sound;
- var _channel:SoundChannel;
- var _SoundTransform:SoundTransform;
- var _position:int;
- var _frameMCSpend:int;
- var mask_play:MovieClip;
- public function DocumentClass() {
- BtnPlay.visible=false;
- // cuplayer.com创建一个声音对象,并播放之
- _sound = new Sound();
- _sound.load(new URLRequest(mp3Url));
- _SoundTransform=new SoundTransform(0.5,0);
- _channel = _sound.play(0,1,_SoundTransform);
- _channel.addEventListener(Event.SOUND_COMPLETE,onSoundEnd);
- mask_play=MovieClip(playBar.getChildByName("mask_play"));
- mask_play.addEventListener(Event.ENTER_FRAME,onBarEnterFrame);
- BtnPlay.addEventListener(MouseEvent.MOUSE_UP,onPlay);
- BtnSuspend.addEventListener(MouseEvent.MOUSE_UP, onPause);
- BtnStop.addEventListener(MouseEvent.MOUSE_UP, onStop);
- BtnBlock.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
- BtnBlock.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
- BtnBlock.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveListener);
- vol.addEventListener(MouseEvent.MOUSE_OUT,mouseOutListener);
- }
- function onSoundEnd(event:Event):void {
- BtnPlay.visible=true;
- BtnSuspend.visible=false;
- _position=0;
- }
- private function onBarEnterFrame(event:Event):void {
- if (_sound.length>0) {
- trace(_sound.bytesTotal);
- trace(_sound.bytesLoaded);
- trace(_sound.length);
- var lengthTotal:int=_sound.bytesTotal/_sound.bytesLoaded*_sound.length;
- playBar.stage.frameRate=1000*mask_play.totalFrames/lengthTotal;
- mask_play.removeEventListener(Event.ENTER_FRAME,onBarEnterFrame);
- }
- }
- function mouseMoveListener(event:MouseEvent):void {
- var newnewSoundTransform:SoundTransform=new SoundTransform((event.stageX-203.3)/80,0);
- _channel.soundTransform=newSoundTransform;
- }
- function mouseDownListener(event:MouseEvent):void {
- var rectang:Rectangle=new Rectangle();
- rectang.x=203.3;
- rectang.y=63.8;
- rectang.height=0;
- rectang.width=80;
- BtnBlock.startDrag(false,rectang);
- }
- function mouseUpListener(event:MouseEvent):void {
- BtnBlock.stopDrag();
- }
- function mouseOutListener(event:MouseEvent):void{
- BtnBlock.stopDrag();
- }
- function onPlay(event:MouseEvent):void {
- mask_play.gotoAndPlay(mask_play.currentFrame);
- _channel = _sound.play(_position);
- BtnSuspend.visible=true;
- BtnPlay.visible=false;
- }
- function onPause(event:MouseEvent):void {
- mask_play.gotoAndStop(mask_play.currentFrame);
- BtnSuspend.visible=false;
- BtnPlay.visible=true;
- _position = _channel.position;
- _channel.stop();
- }
- function onStop(event:MouseEvent):void {
- mask_play.gotoAndStop(null);
- BtnSuspend.visible=false;
- BtnPlay.visible=true;
- _position=0;
- _channel.stop();
- }
- }
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室