cordova捕获音频,并获取文件路径

时间:2018-11-01 10:59:07

标签: javascript cordova audio phonegap capture

我有问题,请帮助我, 我有一个没有界面的录音页面,但是我不知道录制了哪个音轨, 是否有办法知道录制声音的轨迹? 我只想让音轨播放音轨

<!DOCTYPE html>
<html>
<head>
    <title></title> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
   
    <script type="text/javascript" charset="utf-8">
        // Wait for Cordova to load      
        document.addEventListener("deviceready", onDeviceReady, false);
		// PhoneGap is ready
        //
        function onDeviceReady() {
            recordAudio();
        }
        // Record audio
        // 
        function recordAudio() {
            var srcd = "myrecording" + Math.random() + ".wav";
            var mediaRec = new Media(srcd, onSuccess, onError);
            // Record audio
            mediaRec.startRecord();
            // Stop recording after 10 sec
            var recTime = 0;
            var recInterval = setInterval(function () {
                recTime = recTime + 1;
                setAudioPosition(recTime + " sec");
                if (recTime >= 10) {
                    clearInterval(recInterval);
                    mediaRec.stopRecord();
					}
				}, 1000);
		}
		
		 function onSuccess() {

            alert('Uploaded Successfully');
        }
		
        // onError Callback 
        //
        function onError(error) {
            alert('code: ' + error.code + '\n' +
                  'message: ' + error.message + '\n');
        }

        // Set audio position
        // 
        function setAudioPosition(position) {
            document.getElementById('audio_position').innerHTML = position;
        }
    </script>
</head>
<body>
	<button onclick="recordAudio()">Record Audio</button>    
    <p id="media">Recording audio...</p>
    <p id="audio_position"></p>
    <br>
</body>
</html>

0 个答案:

没有答案