🎧 assets_audio_player 🔊

Play music/audio stored in assets files (simultaneously) directly from Flutter (android / ios / web / macos).
You can also use play audio files from network using their url, radios/livestream and local files
Notification can be displayed on Android & iOS, and bluetooth actions are handled
flutter:
assets:
- assets/audios/
AssetsAudioPlayer.newPlayer().open(
Audio("assets/audios/song1.mp3"),
autoStart: true,
showNotification: true,
);

📥 Import
dependencies:
assets_audio_player: ^3.0.8
Works with flutter: ">=3.3.0", be sure to upgrade your sdk
You like the package ? buy me a kofi :)

| Audio Source |
Android |
iOS |
Web |
MacOS |
| 🗄️ Asset file (asset path) |
✅ |
✅ |
✅ |
✅ |
| 🌐 Network file (url) |
✅ |
✅ |
✅ |
✅ |
| 📁 Local file (path) |
✅ |
✅ |
✅ |
✅ |
📻 Network LiveStream / radio (url) (Default, HLS, Dash, SmoothStream) |
✅ |
✅ |
✅ |
✅ |
| Feature |
Android |
iOS |
Web |
MacOS |
| 🎶 Multiple players |
✅ |
✅ |
✅ |
✅ |
| 💽 Open Playlist |
✅ |
✅ |
✅ |
✅ |
| 💬System notification |
✅ |
✅ |
🚫 |
🚫 |
| 🎧 Bluetooth actions |
✅ |
✅ |
🚫 |
🚫 |
| 🔕 Respect System silent mode |
✅ |
✅ |
🚫 |
🚫 |
| 📞 Pause on phone call |
✅ |
✅ |
🚫 |
🚫 |
| Commands |
Android |
iOS |
Web |
MacOS |
| ▶ Play |
✅ |
✅ |
✅ |
✅ |
| ⏸ Pause |
✅ |
✅ |
✅ |
✅ |
| ⏹ Stop |
✅ |
✅ |
✅ |
✅ |
| ⏩ Seek(position) |
✅ |
✅ |
✅ |
✅ |
| ⏪⏩ SeekBy(position) |
✅ |
✅ |
✅ |
✅ |
| ⏩ Forward(speed) |
✅ |
✅ |
✅ |
✅ |
| ⏪ Rewind(speed) |
✅ |
✅ |
✅ |
✅ |
| ⏭ Next |
✅ |
✅ |
✅ |
✅ |
| ⏮ Prev |
✅ |
✅ |
✅ |
✅ |
| Widgets |
Android |
iOS |
Web |
MacOS |
| 🐦 Audio Widget |
✅ |
✅ |
✅ |
✅ |
| 🐦 Widget Builders |
✅ |
✅ |
✅ |
✅ |
| 🐦 AudioPlayer Builders Extension |
✅ |
✅ |
✅ |
✅ |
| Properties |
Android |
iOS |
Web |
MacOS |
| 🔁 Loop |
✅ |
✅ |
✅ |
✅ |
| 🔀 Shuffle |
✅ |
✅ |
✅ |
✅ |
| 🔊 get/set Volume |
✅ |
✅ |
✅ |
✅ |
| ⏩ get/set Play Speed |
✅ |
✅ |
✅ |
✅ |
| ⏩ get/set Pitch |
✅ |
🚫 |
🚫 |
🚫 |
| Listeners |
Android |
iOS |
Web |
MacOS |
| 🦻 Listener onReady(completeDuration) |
✅ |
✅ |
✅ |
✅ |
| 🦻 Listener currentPosition |
✅ |
✅ |
✅ |
✅ |
| 🦻 Listener finished |
✅ |
✅ |
✅ |
✅ |
| 🦻 Listener buffering |
✅ |
✅ |
✅ |
✅ |
| 🦻 Listener volume |
✅ |
✅ |
✅ |
✅ |
| 🦻Listener Play Speed |
✅ |
✅ |
✅ |
✅ |
| 🦻Listener Pitch |
✅ |
🚫 |
🚫 |
🚫 |
📁 Import assets files
No needed to copy songs to a media cache, with assets_audio_player you can open them directly from the assets.
- Create an audio directory in your assets (not necessary named "audios")
- Declare it inside your pubspec.yaml
flutter:
assets:
- assets/audios/
🛠️ Getting Started
final assetsAudioPlayer = AssetsAudioPlayer();
assetsAudioPlayer.open(
Audio("assets/audios/song1.mp3"),
);
You can also play network songs from url
final assetsAudioPlayer = AssetsAudioPlayer();
try {
await assetsAudioPlayer.open(
Audio.network("http://www.mysite.com/myMp3file.mp3"),
);
} catch (t) {
//mp3 unreachable
}
LiveStream / Radio from url
The main difference with network, if you pause/play, on livestream it will resume to present duration
final assetsAudioPlayer = AssetsAudioPlayer();
try {
await assetsAudioPlayer.open(
Audio.liveStream(MY_LIVESTREAM_URL),
);
} catch (t) {
//stream unreachable
}
And play songs from file
//create a new player
final assetsAudioPlayer = AssetsAudioPlayer();
assetsAudioPlayer.open(
Audio.file(FILE_URI),
);
for file uri, please look at https://pub.dev/packages/path_provider
assetsAudioPlayer.playOrPause();
assetsAudioPlayer.play();
assetsAudioPlayer.pause();
assetsAudioPlayer.seek(Duration to);
assetsAudioPlayer.seekBy(Duration by);
assetsAudioPlayer.forwardRewind(double speed);
//if positive, forward, if negative, rewind
assetsAudioPlayer.stop();
Notifications


on iOS, it will use MPNowPlayingInfoCenter
- Add metas inside your audio
final audio = Audio.network("/assets/audio/country.mp3",
metas: Metas(
title: "Country",
artist: "Florent Champigny",
album: "CountryAlbum",
image: MetasImage.asset("assets/images/country.jpg"), //can be MetasImage.network
),
);
- open with
showNotification: true
_player.open(audio, showNotification: true)
Custom notification
Custom icon (android only)
By ResourceName
Make sure you added those icons inside your android/res/drawable !!! not on flutter assets !!!!
await _assetsAudioPlayer.open(
myAudio,
showNotification: true,
notificationSettings: NotificationSettings(
customStopIcon: AndroidResDrawable(name: "ic_stop_custom"),
customPauseIcon: AndroidResDrawable(name:"ic_pause_custom"),
customPlayIcon: AndroidResDrawable(name:"ic_play_custom"),
customPrevIcon: AndroidResDrawable(name:"ic_prev_custom"),
customNextIcon: AndroidResDrawable(name:"ic_next_custom"),
)
And don't forget tell proguard to keep those resources for release mode
(part Keeping Resources)
https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/resource-shrinking
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/ic_next_custom, @drawable/ic_prev_custom, @drawable/ic_pause_custom, @drawable/ic_play_custom, @drawable/ic_stop_custom"/>
By Manifest
Add your icon into your android's res folder (android/app/src/main/res)
Reference this icon into your AndroidManifest (android/app/src/main/AndroidManifest.xml)
<meta-data
android:name="assets.audio.player.notification.icon"
android:resource="@drawable/ic_music_custom"/>
You can also change actions icons
<meta-data
android:name="assets.audio.player.notification.icon.play"
android:resource="@drawable/ic_play_custom"/>
<meta-data
android:name="assets.audio.player.notification.icon.pause"
android:resource="@drawable/ic_pause_custom"/>
<meta-data
android:name="assets.audio.player.notification.icon.stop"
android:resource="@drawable/ic_stop_custom"/>
<meta-data
android:name="assets.audio.player.notification.icon.next"
android:resource="@drawable/ic_next_custom"/>
<meta-data
android:name="assets.audio.player.notification.icon.prev"
android:resource="@drawable/ic_prev_custom"/>
Handle notification click (android)
Add in main
AssetsAudioPlayer.setupNotificationsOpenAction((notification) {
//custom action
return true; //true : handled, does not notify others listeners
//false : enable others listeners to handle it
});
Then if you want a custom action on widget
AssetsAudioPlayer.addNotificationOpenAction((notification) {
//custom action
return false; //true : handled, does not notify others listeners
//false : enable others listeners to handle it
});
Custom actions
You can enable/disable a notification action
open(AUDIO,
showNotification: true,
notificationSettings: NotificationSettings(
prevEnabled: false, //disable the previous button
//and have a custom next action (will disable the default action)
customNextAction: (player) {
print("next");
}
)
)
Update audio's metas / notification content
After your audio creation, just call
audio.updateMetas(
player: _assetsAudioPlayer, //add the player if the audio is actually played
title: "My new title",
artist: "My new artist",
//if I not provide a new album, it keep the old one
image: MetasImage.network(
//my new image url
),
);
Bluetooth Actions
You have to enable notification to make them work
Available remote commands :
- Play / Pause
- Next
- Prev
- Stop