【问题标题】:Flutter Audioplayers ByteSource is not supported on iosiOS 不支持 Flutter Audioplayers ByteSource
【发布时间】:2023-01-22 20:25:14
【问题描述】:

我一直在尝试在我的 flutter 项目中实现 amazon polly,但我无法在 iOS 设备上运行它。它在 android 上工作得很好。我使用的是 iOS 不支持的字节源。

BytesSource source = BytesSource(bytes);
await audioPlayer.play(source);

在文档中写道:

/// Source containing the actual bytes of the media to be played.
///
/// This is currently only supported for Android (SDK >= 23).

所以我的问题是如何使用 audioplayers 包在 iOS 或 macOS 设备中播放字节?我是否需要使用其他软件包或是否有可用的解决方法?

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    audioplayers 包支持从各种来源播放音频,包括文件、网络流和资产,但目前不支持从 iOS 或 macOS 上的 ByteSource 播放音频。 有几种方法可以解决此限制:

    1. 将 ByteSource 转换为文件并使用 audioplayers 包中的 AudioCache 类来播放该文件。
    2. 使用不同的包,例如支持在所有平台(包括 iOS 和 macOS)上播放来自 ByteSource 的音频的 audio_service。
    3. flutter_sound 包支持在所有平台(包括 iOS 和 macOS)上播放来自 ByteData 的音频。 重要的是要注意,当在 iOS 上播放来自 ByteSource 的音频时,您需要了解 iOS 数据保护功能,该功能会加密磁盘上的文件,因此当设备被锁定和/或应用程序终止时,文件是无法访问。

      建议您在 iOS 和 macOS 设备上测试您的音频播放解决方案,以确保它按预期工作。

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 1970-01-01
      • 2018-09-21
      • 2020-02-16
      • 2022-11-22
      • 2020-07-12
      • 2020-04-08
      • 2020-10-12
      • 1970-01-01
      相关资源
      最近更新 更多