无法在IOS上的离子应用程序中录制和保存音频

时间:2015-12-17 11:13:39

标签: ios file cordova ionic-framework media

我正在创建一个记录音频并将其存储到持久位置的离子应用程序,而它在Android上完美运行,IOS让我变得疯狂。

这是我正在使用的代码

创建目录的代码

if (ionic.Platform.isAndroid()) {
  console.log('ok..its android. setting base dir path');
  $rootScope.dirBasePath = cordova.file.externalRootDirectory;
} else if (ionic.Platform.isIOS()) {
  console.log('it is ios, setting base path');
  $rootScope.dirBasePath = cordova.file.dataDirectory;
}

console.log($rootScope.dirBasePath);
// create directory for audio recordings
$cordovaFile.createDir($rootScope.dirBasePath, "corrit", false)
.then(function (success) {
  console.log('created dir '+JSON.stringify(success));
}, function (error) {
  console.log('error creating dir '+JSON.stringify(error));
});

目录正在两个平台上成功创建

这是重新编码音频文件的代码

timestamp = new Date()
if (ionic.Platform.isAndroid()) {
    $scope.audioFileName = timestamp.getTime()+'.amr';
} else if (ionic.Platform.isIOS()) {
    $scope.audioFileName = timestamp.getTime()+'.wav';
}
$scope.data.audioSrc = $rootScope.dirBasePath+'corrit/'+$scope.audioFileName;
console.log($scope.data.audioSrc);
$scope.data.media = $cordovaMedia.newMedia($scope.data.audioSrc);

console.log('recording audio...');
$scope.data.media.startRecord();

这是播放音频文件的代码

console.log('stoping audio...');
$scope.data.media.stopRecord();
$scope.data.media.play();

这是ios的控制台日志

created dir {"isFile":false,"isDirectory":true,"name":"corrit","fullPath":"/corrit/","filesystem":"<FileSystem: library-nosync>","nativeURL":"file:///var/mobile/Containers/Data/Application/C07AA015-63B3-4B10-8032-08B0352F06F0/Library/NoCloud/corrit/"}

record audio
file:///var/mobile/Containers/Data/Application/C07AA015-63B3-4B10-8032-08B0352F06F0/Library/NoCloud/corrit/1450348328418.wav
recording audio...
THREAD WARNING: ['Media'] took '575.528076' ms. Plugin should use a background thread.
exeption nativeEvalAndFetch : TypeError: undefined is not an object (evaluating 'a.reject')
stoping audio...
Failed to initialize AVAudioPlayer: The operation couldn’t be completed. (OSStatus error 2003334207.)
THREAD WARNING: ['Media'] took '18.506104' ms. Plugin should use a background thread.

我的猜测是该文件没有记录指定的路径

出了什么问题?

由于

0 个答案:

没有答案