Flutter 播放本地音频

首先导入插件

  # 播放本地音频
  soundpool: ^2.3.0

然后引入你要使用的音频地址

  assets:
    - assets/images/
    - assets/audio/

 

然后使用下面的代码就可以实习了

  /// 播放音频
  Soundpool soundpool = Soundpool(streamType: StreamType.notification);

  Future playSound() async {
    int soundId = await rootBundle
        .load('assets/audio/car_jine.wav')
        .then(((ByteData soundDate) {
      return soundpool.load(soundDate);
    }));
    soundpool.setVolume(volume: 0.5);
    await soundpool.play(soundId);
  }

你可能感兴趣的:(flutter,音视频,javascript)