[AS3]AS3录音回放与保存
[AS3]AS3录音回放与保存
系统要求:flash CS5以上(保证flashplayer播放器10.2以上),需要几个第三方的 类,org.as3wavsound.WavSound,org.bytearray.micrecorder.MicRecorder,org.bytearray.micrecorder.encoder.WaveEncoder, org.bytearray.micrecorder.events.RecordingEvent,附件里面有。
打开flash CS5,新建AS3文档,舞台上放置四个按钮:btn1、btn2、btn3、btn4,两个动态文本框:txtMsg、displayMsg,
第一帧写代码:
- import flash.display.StageAlign;
- import flash.display.StageScaleMode;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.media.Microphone;
- import org.as3wavsound.WavSound;
- import org.bytearray.micrecorder.MicRecorder;
- import org.bytearray.micrecorder.encoder.WaveEncoder;
- import org.bytearray.micrecorder.events.RecordingEvent;
- stage.align = StageAlign.TOP_LEFT;
- stage.scaleMode = StageScaleMode.NO_SCALE;
- var recorder:MicRecorder = new MicRecorder( new WaveEncoder() );
- var player:WavSound;
- var _file:FileReference = new FileReference();
- recorder.addEventListener(RecordingEvent.RECORDING, onRecording);
- recorder.addEventListener(Event.COMPLETE, onRecordComplete);
- btn2.visible = false;
- btn3.visible = false;
- btn4.visible = false;
- btn1.addEventListener(MouseEvent.CLICK, startRecord);
- btn2.addEventListener(MouseEvent.CLICK, stopRecord);
- btn3.addEventListener(MouseEvent.CLICK, playBack);
- btn4.addEventListener(MouseEvent.CLICK, saveFile);
- function startRecord(event:MouseEvent):void
- {
- txtMsg.text = "正在录音";
- recorder.record();
- btn1.visible = false;
- btn2.visible = true;
- btn3.visible = false;
- }
- function stopRecord(event:MouseEvent):void
- {
- txtMsg.text = "录制完成,可以播放";
- recorder.stop();
- btn1.visible = true;
- btn2.visible = false;
- btn3.visible = true;
- btn4.visible = true;
- }
- function playBack(event:MouseEvent):void
- {
- txtMsg.text = "正在播放";
- player = new WavSound(recorder.output);
- player.play();
- btn1.visible = true;
- btn2.visible = true;
- btn3.visible = true;
- }
- function saveFile(event:MouseEvent):void
- {
- _file.save( recorder.output, "recorded.wav" );
- }
- function onRecording(event:RecordingEvent):void
- {
- displayMsg.text = "Recording since : " + event.time + " ms.";
- }
- function onRecordComplete(event:Event):void
- {
- //
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...