【问题标题】:Ionic V5 Capacitor - cordova-plugin-media Error code 1离子 V5 电容器 - cordova-plugin-media 错误代码 1
【发布时间】:2021-10-10 05:58:49
【问题描述】:

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

我还添加了<application android:requestLegacyExternalStorage="true" /><edit-config>

版本

  • ionic-native/app-version: "^5.33.1"
  • 电容器/cli:“^2.4.8”
  • 电容器/机器人:“^2.4.6”
  • cordova-plugin-media: "^5.0.3"
  • @ionic-native/file: "^5.34.0"

代码示例:

  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;
  }

【问题讨论】:

    标签: android angular ionic-framework capacitor recorder


    【解决方案1】:

    由于 Android 11+ (SDK 30+),您无法将文件写入 Documents 或 ExternalStorage。

    更改您写入文件的 DIR。 (this.filePath)

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-12
      • 2023-03-11
      • 2019-08-14
      • 1970-01-01
      • 2021-03-01
      • 1970-01-01
      相关资源
      最近更新 更多