使用第三方插件实现音频播放,支持安卓、IOS
先上官网链接:pub.dev/packages/au…
安装
根目录打开 pubspec.yaml 找到dependencies, 添加
audioplayers: ^0.13.1
控制台:(有些编辑器会自动帮你安装)
flutter pub get
使用
引用
import 'package:audioplayers/audio_cache.dart';
初始化
static AudioCache audioPlayer = AudioCache(prefix: 'audio/');
播放
audioPlayer.play('di.mp3');
pubspec.yaml文件
flutter:assets:- assets/audio/di.mp3
文件路径

播放本地音频文件
使用audio_cache
https://github.com/luanpotter/audioplayers/blob/master/doc/audio_cache.md
