系统要求: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
- {
- //
- }
复制代码 发布测试,记得运行使用麦克风。
源码下载:
AS3本地录音及回放保存.rar
(353.3 KB, 下载次数: 140)
来自群组: FLASH动画与程序设计 |