【问题标题】:Expo AV audio not playing on iOS/ iPhoneExpo AV 音频无法在 iOS/iPhone 上播放
【发布时间】:2021-01-15 12:51:10
【问题描述】:

我使用 Expo AV 并在我的应用程序中开发了一个屏幕来播放从我的服务器获取的音频文件。它在 Android 上运行良好,但在 iPhone 上无法播放。

当我播放按钮来播放加载和播放文件的音频时

soundObject.loadAsync({ uri: this.state.file });
soundObject.playAsync();

它返回一个错误:

不支持此媒体格式。 - AVPlayerItem 实例失败,错误代码 -11828 和域“AVFoundationErrorDomain”。

这是我加载和播放音频的代码:

async loadAudio() {
soundObject = new Audio.Sound();
try {
await soundObject.loadAsync({ uri: this.state.file });
console.log("File loaded: " + this.state.file);
} catch (error) {
console.log(error);
}
}


async playAudio() {
if (!this.state.isPlayingAudio) {
try {
  
  await soundObject.playAsync();
} catch (error) {
  console.log(error);
}

  else {
soundObject.pauseAsync();
  }
  }

我在录制和获取文件时尝试将音频格式更改为 m4a、wav、caf,但这并没有帮助 我在 iPhone 7 plus、iOS 14.2 上运行该应用程序 请问有什么建议/修复吗?提前致谢

【问题讨论】:

  • 我也面临同样的问题。这些文件可以在 Android 上播放,但不能在 iOS 上播放。你找到解决办法了吗?
  • 可以播放.wav格式的文件

标签: ios react-native expo audio-streaming expo-av


【解决方案1】:

你调用 loadAsync 不正确。

调用应该如下所示:

await Audio.Sound.createAsync(
  { uri: this.state.file },
  { shouldPlay: true }
);

【讨论】:

    【解决方案2】:

    我将 uri 对象和第二个参数 {shouldPlay: true} 传递给 loadAsync 方法。 这会从亚马逊服务器 s3 播放我的 mp3 文件

    await Audio.Sound.loadAsync( { uri: this.state.file }, { shouldPlay: true } )

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案3】:

    我参加了 44 世博会,降级到 43 世博会成功了。运行expo upgrade 43

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-19
      • 2022-09-23
      • 2021-11-11
      • 2012-03-28
      • 2012-03-22
      • 1970-01-01
      • 2020-08-23
      • 2023-01-18
      相关资源
      最近更新 更多