【问题标题】:Audio_cache (audioplayers package) can't play audio file in androidAudio_cache(audioplayers 包)无法在 android 中播放音频文件
【发布时间】:2021-01-18 04:56:29
【问题描述】:

今天,我制作了在 Android 上播放音乐的应用程序。 使用 MediaPlayer 播放音频文件失败;它无法播放任何文件音频。 在调试控制台上:

I/flutter ( 5455): taped
E/MediaPlayerNative( 5455): error (1, -2147483648)
E/MediaPlayer( 5455): Error (1,-2147483648)
E/MediaPlayerNative( 5455): pause called in state 0, mPlayer(0xc83ffa40)
E/MediaPlayerNative( 5455): error (-38, 0)
E/MediaPlayerNative( 5455): Attempt to perform seekTo in wrong state: mPlayer=0xc83ffa40, mCurrentState=0
E/MediaPlayerNative( 5455): error (-38, 0)
2
E/MediaPlayer( 5455): Error (-38,0)

这是我的代码:

Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          FlatButton.icon(
            label: Text('ss'),
            icon: Icon(Icons.ac_unit_outlined),
            onPressed: () {
              print('taped');
              final player = AudioCache();
              player.play('yagami.wav');
            },
          ),
        ],
      ),
    );
  }

在 pubspec.yaml 上:

dependencies:
  audioplayers: 0.17.0 

我尝试过旧版本的软件包,但没有成功。 如何解决这个问题呢? 或任何其他在资产上播放音频的包?

【问题讨论】:

    标签: flutter flutter-dependencies


    【解决方案1】:

    可能有帮助的方法是在开始时只创建一次播放器,而不是每次按下按钮,因为这违背了 AudioCache 的目的。 所以从 OnPressed 函数中删除 final player = AudioCache();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多