How to play local mp3 file with audioplayer plugin in Flutter

元气小坏坏 提交于 2019-11-28 20:55:47

The audioplayer plugin currently only supports network paths and files. You can move an asset to a temporary folder and play it with this code:

import 'package:path_provider/path_provider.dart';

...

final file = new File('${(await getTemporaryDirectory()).path}/music.mp3');
await file.writeAsBytes((await loadAsset()).buffer.asUint8List());
final result = await audioPlayer.play(file.path, isLocal: true);

I have just created a repo in github that uses audioplayers plugin to stream local mp3 files. This player can seek, pause, stop and play local audio

https://github.com/samupra/local_flutter_audio_player

A way that worked for me was to create the assets file and load the mp3 file in to the directory.

Then load the file using the Future AudioPlayer audio = await AudioCache.play("filetobeloaded.mp3");

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!