Phonegap媒体记录第二次不起作用

时间:2013-10-03 17:27:38

标签: javascript jquery cordova

我正在尝试使用phonegap录制音频。当我单击我的记录按钮时,函数recordAudio()成功执行。但是第二次日志会出错。音频源是可以的,但我不知道该错误意味着什么。这是错误:

E/AudioRecord( 40): could not get audio input for record source 1
e/stagefrightrecorder ( 40): audio source is not initialized
e/mediarecorder( 2676): start failed -2147483648
d/cordovalog( 2676): file:///android_asset/www/phonegap.js: line 862 : uncaught error: error calling method on NPObject

这是我的代码:

var my_mediaRec=null;
        var recInterval=null;
        // Record audio
        //
        function recordAudio(){

            my_mediaRec = new Media(fs_path+"/recording"+lesson_no+".mp3", onSuccessRecord, onError);

            // Record audio
            my_mediaRec.startRecord();

            recInterval = setInterval(function() {
                endWord++;
                placeRecordMarker(endWord)
            }, 1000);

        }

1 个答案:

答案 0 :(得分:0)

这是html:

<div id="record-buttons">
                        <div class="record-mic" onclick="record_mic()"></div>
                        <div class="record-stop" onclick="record_play()"></div>
                        <div class="record-play" onclick="record_stop()"></div>
                    </div>

这是js:

    function record_play(){
        if(recording==true){
            $('.record-play').show();
            $('.record-stop').hide();
            endWord=startWord;
            recordAudio();
        }
    } 
    function record_stop(){
        if(recording==true){
            $('.record-stop').show();
            $('.record-play').hide();
            startWord=endWord;
            stopRecordAudio();

        }
    } 

var my_mediaRec=null;
        var recInterval=null;
        // Record audio
        //
        function recordAudio(){

            my_mediaRec = new Media(fs_path+"/recording"+lesson_no+".mp3", onSuccessRecord, onError);

            // Record audio
            my_mediaRec.startRecord();

            recInterval = setInterval(function() {
                endWord++;
                placeRecordMarker(endWord)
            }, 1000);

        }

        // Set record position
        //
        /*function setRecordPosition(position){
            $('.audio-position').html(position);
            //placeMarker(position)
        }*/

        function stopRecordAudio(){
            clearInterval(recInterval);
            my_mediaRec.stopRecord();
        }