[AS3]mp3音乐播放器实例源代码参考
[AS3]mp3音乐播放器实例源代码参考,mp3音乐播放器,音乐播放器
[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();
- }
- }
- }
热门文章推荐
- 纯HLS(m3u8)跨平台技术(HLSPlayer,m3u8Player跨平台多终端)
- DiscuzX3.2酷播视频插件(dz论坛自定义视频插件带广告
- [微信视频]实现网站中的视频在微信平台上正常播放(超多组图)
- [rtsp]海康威视监控摄像头实现web端无插件监控实拍效果
- 很酷,酷播wordpress视频插件(支持PC/安卓/苹果跨平台播放)
- [组图]微信视频技术:支持微信视频直播和视频点播
- [AS3]as3.0的rtmp流媒体播放器写法源代码示例
- 一步一步教你制作FLV网页视频播放器
请稍候...