我目前正在开发一个允许用户录制音频消息的项目,但是最近有一个请求允许他们暂停录制过程然后继续录制(添加新音频以跟随之前的录制) 。
示例:
我目前正在使用 recorder.js ,并且到目前为止对它非常满意,但是我觉得它缺少我正在寻找的功能而且我对Flash不够熟悉/ Actionscript要深入挖掘并修补。
我很好奇是否有任何用户对全功能解决方案有任何建议或建议如何实现类似的东西。一个相当跨浏览器/跨平台的解决方案将是首选,但不是一个硬性要求(主要涉及Chrome和IE)。
答案 0 :(得分:0)
参考以下代码。
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.utils.ByteArray;
import flash.events.Event;
var microphone:Microphone;
var isPause:Boolean = false;
var soundRecording:ByteArray;
record_btn.addEventListener(MouseEvent.CLICK, onRecordStart);
recordPause_btn.addEventListener(MouseEvent.CLICK, onPauseResumeToggle);
recordStop_btn.addEventListener(MouseEvent.CLICK, onRecordStop);
audioPlay_btn.addEventListener(MouseEvent.CLICK, onPlay);
function onRecordStart(e:MouseEvent=null):void
{
soundRecording = new ByteArray();
microphone=Microphone.getMicrophone();
microphone.rate=44;
}
function onPauseResumeToggle(e:MouseEvent=null):void
{
if(!isPause)
{
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
else
{
microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
isPause != isPause;
}
function onRecordStop(e:MouseEvent=null):void
{
isPause = false;
microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
soundRecording.position=0;
}
function gotMicData(micData:SampleDataEvent):void
{
soundRecording.writeBytes(micData.data);
}
function onPlay(e:MouseEvent=null):void
{
soundRecording.position=0;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);
soundOutput.play();
}
function playSound(soundOutput:SampleDataEvent):void
{
if (! soundRecording.bytesAvailable>0)
{
return;
}
for (var i:int = 0; i < 8192; i++)
{
var sample:Number=0;
if (soundRecording.bytesAvailable>0)
{
sample=soundRecording.readFloat();
}
soundOutput.data.writeFloat(sample);
soundOutput.data.writeFloat(sample);
}
}
答案 1 :(得分:0)