问题描述
我正在使用 Phonegap 创建一个 Android 应用程序(录音机),但我的代码中有这两个错误:
I'm using Phonegap to create an Android application (Voice Recorder), but I had these 2 errors in my code:
ReferenceError: Can't find variable: Media.
TypeError: 表达式mediaRec"未定义的结果不是对象.
第一个错误发生在应用程序运行时.第二个错误发生在我调用 recordAudio(); 时.方法.
The first error happens when the application runs. The second error happens when I call the recordAudio(); method.
如果你知道,请告诉我有什么问题.
Tell me what's the problem please if you know.
var mediaRec;
var src;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
}
function init() {
document.getElementById('status').innerHTML = "Recording Status";
src = "myrecording.mp3";
mediaRec = new Media(src, onSuccess, onError);
}
function recordAudio() {
// 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);
}
}, 1000);
}
// Stop audio
function stopRecording() {
if (mediaRec) {
mediaRec.stopRecord();
}
clearInterval(mediaTimer);
mediaTimer = null;
}
// onSuccess Callback
function onSuccess() {
console.log("recordAudio():Audio Success");
}
// onError Callback
function onError(error) {
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
}
// Set audio position
function setAudioPosition(position) {
document.getElementById('rec_position').innerHTML = position;
}
谢谢.
推荐答案
我认为 scr = "/android_asset/www/myrecording.mp3" 因为目录 phonegap 在 asset/www/...如果在 phonegap 中找不到目录,javascript 会显示类似 ReferenceError: Can't find variable: Media 的警报.
I think scr = "/android_asset/www/myrecording.mp3" because directory phonegap in asset/www/...If directory not found javascript in phonegap show alert like that ReferenceError: Can't find variable: Media.
这篇关于Javascript 找不到这些变量,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!