首页 > 解决方案 > Cordova 媒体插件 ios“无法使用 AVAudioRecorder 代码开始录制:1”

问题描述

这个问题之前被问过,但它接受的答案不起作用。问题是我无法使用 cordova/ionic 2 应用程序在 ios 上录制音频,我尝试了 ionic native 失败且没有错误,现在尝试给出错误的 cordova-media-plugin:"Failed to start recording using AVAudioRecorder code:1". 这是我的代码

      this.file.createFile(this.dir, this.filename, true).then(f => {
        this.m = new (<any>window).Media(this.dir + this.filename,function(e){alert('Success');},
    function(e){alert('failed'+JSON.stringify(e));});
this.m.startRecord();
   }).catch(e=>alert(JSON.stringify(e)));

this.dir具有 tempDirectory 的值和文件名是 .wav 与 mp3 相同的结果

请帮忙,谢谢

标签: ioscordovaionic2cordova-media-plugin

解决方案


在此插件的旧版本(cordova 3.0)上,这可能是一个许可问题,代码 1 是:

缺少 Android 权限

为确保您有录制权限,您可以使用此插件

一个例子 :

cordova.plugins.diagnostic.isMicrophoneAuthorized(function(authorized){
    if (authorized) {
        // Do something
    } else {
        // Do something else
    }
}, function(error){
    console.error(error);
});

推荐阅读