首页 > 解决方案 > 离子 V5 电容器 - cordova-plugin-media 错误代码 1

问题描述

我已经安装了插件并检查了所有需要的权限,但仍然在媒体插件上收到错误代码 1。

我也加<application android:requestLegacyExternalStorage="true" /><edit-config>

版本

代码示例:

  startRecording() {
    if (this.platform.is('ios')) {
      this.fileName = 'record' + new Date().getDate() + new Date().getMonth() + new Date().getFullYear() + new Date().getHours() + new Date().getMinutes() + new Date().getSeconds() + '.mp3';
      this.filePath = this.file.documentsDirectory.replace(/file:\/\//g, '') + this.fileName;
      this.audio = this.media.create(this.filePath);
    } else if (this.platform.is('android')) {
      this.fileName = 'record' + new Date().getDate() + new Date().getMonth() + new Date().getFullYear() + new Date().getHours() + new Date().getMinutes() + new Date().getSeconds() + '.mp3';
      this.filePath = this.file.externalDataDirectory + this.fileName;
      this.audio = this.media.create(this.filePath);
    }
    this.audio.onStatusUpdate.subscribe(status => {
      console.log("status", status)
    });

    this.audio.onSuccess.subscribe(() => {
      console.log("success")
    });

    this.audio.onError.subscribe(error => {
      console.log("error", error)
    });

    this.audio.startRecord();
    this.recording = true;
  }

标签: androidangularionic-frameworkcapacitorrecorder

解决方案


Since Android 11+ (SDK 30+) you can't write files to Documents or ExternalStorage.

Change the DIR you write your files to. (this.filePath)

See: https://developer.android.com/about/versions/11/privacy/storage


推荐阅读