• pubsepc.yaml 文件

    flutter:
      assets:
        video/video-01.mp4
        video/video-02.mp4
        audio/bg.mp3
    

    以上关于视频的文件的配置,都能正常播放(使用的 chewie 插件)

    到了 audioplayers 插件,就是不能播,报错:找不到文件资源

    Unable to load asset

  • 也注意到了,区分本地文件与网络文件

    网络用 AudioPlayer,也可以通过指定 isLocal: true 来播放本地文件

    本地文件,用 AudioCache 类。

  • 迷惑之际,寻根源码

    audio_cache.dart

    Future<ByteData> _fetchAsset(String fileName) async {
      return await rootBundle.load('assets/$prefix$fileName');
    }
    

    看到这,这不是给固定加了个 assets 的路径吗

  • 修改尝试

    flutter:
      assets:
        video/video-01.mp4
        video/video-02.mp4
        assets/audio/bg.mp3
    

    同时,根目录下也做相同路径
    audio/bg.mp3 -> assets/audio/bg.mp3

播放成功!


相关文章:

  • 2021-11-30
  • 2021-08-13
  • 2022-12-23
  • 2021-07-20
  • 2021-11-19
猜你喜欢
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2021-06-19
  • 2022-12-23
相关资源
相似解决方案