我正在使用ngCordova尝试在离子框架应用程序中录制音频。当我在带有iOS 9.1的iPhone 6上运行它时,代码正在运行但是抛出以下消息:
exeption nativeEvalAndFetch:TypeError:undefined不是对象(评估' q.notify')
(是的异常在错误中以这种方式拼写)。
我的代码:
$scope.startRecording = function () {
console.log("In Start Recording Method!")
if (ionic.Platform.isIOS()) {
console.log("It's iOS!");
var d = new Date();
var epochSeconds = d.getTime();
var audioFileName = $scope.input.sectionName+epochSeconds;
$scope.input.audioFileName = audioFileName;
$scope.input.mediaSrc = "documents://"+ $scope.input.audioFileName + ".wav";
} else if (ionic.Platform.isAndroid()) {
console.log("It's Android!");
var d = new Date();
var epochSeconds = d.getTime();
var audioFileName = $scope.input.sectionName+epochSeconds;
$scope.input.audioFileName = audioFileName;
$scope.input.mediaSrc = $scope.input.audioFileName + ".amr";
}
console.log("Setting media src to: " + $scope.input.mediaSrc)
console.log("Creating media object.");
$scope.input.disableStartRecord = true;
$scope.input.disableStopRecord = false;
var mediaObj = $cordovaMedia.newMedia($scope.input.mediaSrc,
// success callback
function() {
console.log("recordAudio():Audio Success");
},
// error callback
function(err) {
console.log("recordAudio():Audio Error: "+ err.code);
});
$scope.mediaObj = mediaObj;
console.log("Starting recording...");
$scope.mediaObj.startRecord();
}
$scope.stopRecording = function () {
console.log("Recording stopped to: " + $scope.input.audioFileName);
$scope.input.disableStartRecord = true;
$scope.input.disableStopRecord = true;
$scope.mediaObj.stopRecord();
$scope.mediaObj.release();
}
Xcode控制台中的输出:
2015-10-28 22:05:12.845 APPNAME INFO In Start Recording Method!
2015-10-28 22:05:12.845 APPNAME INFO It's iOS!
2015-10-28 22:05:12.845 APPNAME INFO Setting media src to: documents://DateTimeAudioNote1446084312826.wav
2015-10-28 22:05:12.845 APPNAME INFO Creating media object.
2015-10-28 22:05:12.848 APPNAME INFO Starting recording...
2015-10-28 22:05:12.848 APPNAME INFO Will use resource 'documents://DateTimeAudioNote1446084312826.wav' from the documents folder with path = /var/mobile/Containers/Data/Application/604C8650-9F24-41B4-ABC5-A73514B5AC8F/Documents/DateTimeAudioNote1446084312826.wav
2015-10-28 22:05:13.019 APPNAME INFO Started recording audio sample 'documents://DateTimeAudioNote1446084312826.wav'
2015-10-28 22:05:13.023 APPNAME INFO THREAD WARNING: ['Media'] took '174.710938' ms. Plugin should use a background thread.
2015-10-28 22:05:13.046 APPNAME INFO exeption nativeEvalAndFetch : TypeError: undefined is not an object (evaluating 'q.notify')
2015-10-28 22:05:26.376 APPNAME INFO Recording stopped to: DateTimeAudioNote1446084312826
2015-10-28 22:05:26.377 APPNAME INFO Stopped recording audio sample 'documents://DateTimeAudioNote1446084312826.wav'
2015-10-28 22:05:26.385 APPNAME INFO Finished recording audio sample 'documents://DateTimeAudioNote1446084312826.wav'
2015-10-28 22:05:26.558 APPNAME INFO Media with id 2ad5f343-b6fb-37c4-27de-b3a5e51e3146 released
2015-10-28 22:05:26.603 APPNAME INFO exeption nativeEvalAndFetch : TypeError: undefined is not an object (evaluating 'q.notify')
2015-10-28 22:07:17.893 APPNAME INFO Audio Record Popup Closed.
有什么想法吗?
答案 0 :(得分:0)
我切换到了cordova-plugin-media-capture插件,它完全按照我的需要工作,甚至提供了一个简单但足够好的用于录制的UI。基本片段:
var options = { limit: 1, duration: 30 };
$cordovaCapture.captureAudio(options).then(function(audioData) {
console.log("Audio captured successfully!");
// Success! Audio data is here
var i, path, len;
for (i = 0, len = audioData.length; i < len; i += 1) {
path = audioData[i].fullPath;
console.log("The recorded file is at: " + path);
console.log("Moving file to data directory.")
onAudioSuccess("file://"+path);
}
},fail}
所以...如果你想录制音频,请使用cordova捕获。