0

我使用媒体记录器(html5-audio-record)在 android webview 中录制音频,这是可行的,但有时我没有收到任何数据并且 blob 没有改变!我关闭了我的 android 活动,并且每次测试的状态都是固定的,但是第一次运行良好,下一次运行不正常。为什么当我停止录制时 e.data 为空?

JS代码:

navigator.mediaDevices.getUserMedia(
              {audio : true}
            ).then(function(stream) {
                chunks[index] = [];
                recorder[index] = new MediaRecorder(stream);
                recorder[index].ignoreMutedMedia = false;

                recorder[index].ondataavailable = function(e) {
                        chunks[index].push(e.data);
                    if (recorder[index].state == 'inactive') {
                        var blob = new Blob(chunks[index], { type: 'audio/webm' });
                        recorder[index].ondataavailable = null;
                        uploadFile(blob, index);
                    }
                };

                if(recorder[index] != 'recording')                   
                    recorder[index].start(1000); //recorder[index].start();

            }).catch(function(index) {
                    microphoneError();
            });

在此处输入图像描述

4

1 回答 1

0

我通过将这些代码添加到 activity.java 解决了这个问题!

@Override
protected void onDestroy() {
    myWebView.destroy();
    myWebView = null;
    super.onDestroy();
}
于 2020-01-22T08:58:03.423 回答