应用思考-教育技术论坛

标题: AS3与本地文件交互之——录音回放保存 [打印本页]

作者: etthink    时间: 2013-8-4 22:59
标题: 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,
第一帧写代码:
  1. import flash.display.StageAlign;
  2. import flash.display.StageScaleMode;
  3. import flash.events.Event;
  4. import flash.events.MouseEvent;
  5. import flash.media.Microphone;

  6. import org.as3wavsound.WavSound;
  7. import org.bytearray.micrecorder.MicRecorder;
  8. import org.bytearray.micrecorder.encoder.WaveEncoder;
  9. import org.bytearray.micrecorder.events.RecordingEvent;

  10. stage.align = StageAlign.TOP_LEFT;
  11. stage.scaleMode = StageScaleMode.NO_SCALE;

  12. var recorder:MicRecorder = new MicRecorder( new WaveEncoder() );
  13. var player:WavSound;
  14. var _file:FileReference = new FileReference();

  15. recorder.addEventListener(RecordingEvent.RECORDING, onRecording);
  16. recorder.addEventListener(Event.COMPLETE, onRecordComplete);

  17. btn2.visible = false;
  18. btn3.visible = false;
  19. btn4.visible = false;

  20. btn1.addEventListener(MouseEvent.CLICK, startRecord);
  21. btn2.addEventListener(MouseEvent.CLICK, stopRecord);
  22. btn3.addEventListener(MouseEvent.CLICK, playBack);
  23. btn4.addEventListener(MouseEvent.CLICK, saveFile);

  24. function startRecord(event:MouseEvent):void
  25. {
  26. txtMsg.text = "正在录音";
  27. recorder.record();
  28. btn1.visible = false;
  29. btn2.visible = true;
  30. btn3.visible = false;
  31. }
  32. function stopRecord(event:MouseEvent):void
  33. {
  34. txtMsg.text = "录制完成,可以播放";
  35. recorder.stop();
  36. btn1.visible = true;
  37. btn2.visible = false;
  38. btn3.visible = true;
  39. btn4.visible = true;
  40. }
  41. function playBack(event:MouseEvent):void
  42. {
  43. txtMsg.text = "正在播放";
  44. player = new WavSound(recorder.output);
  45. player.play();

  46. btn1.visible = true;
  47. btn2.visible = true;
  48. btn3.visible = true;
  49. }
  50. function saveFile(event:MouseEvent):void
  51. {
  52. _file.save( recorder.output, "recorded.wav" );
  53. }

  54. function onRecording(event:RecordingEvent):void
  55. {
  56. displayMsg.text = "Recording since : " + event.time + " ms.";
  57. }
  58. function onRecordComplete(event:Event):void
  59. {
  60. //
  61. }
复制代码
发布测试,记得运行使用麦克风。
源码下载: (, 下载次数: 131)
[groupid=192]FLASH动画与程序设计[/groupid]




欢迎光临 应用思考-教育技术论坛 (http://etthink.com/) Powered by Discuz! X3.4