MediaRecorder-如何“清除” blob数据/创建新记录?

时间:2018-09-16 13:14:51

标签: cordova audio phonegap mediarecorder recording

我正在使用Phonegap MediaRecorder在IOS上录制一些音频。有一个录音,停止录音和播放按钮。效果很好,除非当我再次点击“录制/停止”以尝试进行其他录制时,它仍会播放我制作的第一张录音。

如何在每次单击记录按钮或“清除”斑点数据时覆盖以前的记录?谢谢。

    document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log("device ready to go.");
    console.log(navigator.mediaDevices.getUserMedia);
}



navigator.mediaDevices.getUserMedia({
    'audio': true
}).then(function(mediastream) {
    var options = { mimeType : 'audio/wav'};
    var mediaRecorder = new MediaRecorder(mediastream, options);

//start recording

Appery("RecordAudioButton").click(function() {
               mediaRecorder.start();
        console.log(mediaRecorder.state);
               console.log("recorder started");

           });

//stop recording

Appery("StopRecord").click(function() {
              mediaRecorder.stop();
          console.log(mediaRecorder.state);
               console.log("recorder stopped");

           });

//play recording

mediaRecorder.ondataavailable = function(blob) {
    var audioURL = mediaRecorder.src;
    if(device.platform === 'iOS') {                 // iOS ; cordova-plugin-device required for this check
        Appery("audioPlayer").attr("src", audioURL);
    } else {
        var recordedChunks = [];
        recordedChunks.push(blob.data);
        audioURL.src = URL.createObjectURL(new Blob(recordedChunks));   // Android device
    }
};


});

1 个答案:

答案 0 :(得分:0)

尝试在ondataavailable函数的开头将audioURL.src设置为null