assets_audio_player_web 2.0.7+9

  • Readme
  • Changelog
  • Installing
  • 95

๐ŸŽง assets_audio_player ๐Ÿ”Š #

pub package Awesome Flutter

Codemagic build status CodeFactor

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

    - assets/audios/
    autoPlay: true,
    showNotification: true,

sample1 sample1

๐Ÿ“ฅ Import #

  assets_audio_player: ^2.0.7+8

Works with flutter: ">=1.12.13+hotfix.6 <2.0.0", be sure to upgrade your sdk

You like the package ? buy me a kofi :)

Buy Me a Coffee at

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 โœ… โœ… โœ… โœ…
Listeners Android iOS Web MacOS
๐Ÿฆป Listener onReady(completeDuration) โœ… โœ… โœ… โœ…
๐Ÿฆป Listener currentPosition โœ… โœ… โœ… โœ…
๐Ÿฆป Listener finished โœ… โœ… โœ… โœ…
๐Ÿฆป Listener buffering โœ… โœ… โœ… โœ…
๐Ÿฆป Listener volume โœ… โœ… โœ… โœ…
๐ŸฆปListener Play Speed โœ… โœ… โœ… โœ…

๐Ÿ“ Import assets files #

No needed to copy songs to a media cache, with assets_audio_player you can open them directly from the assets.

  1. Create an audio directory in your assets (not necessary named "audios")
  2. Declare it inside your pubspec.yaml
    - assets/audios/

๐Ÿ› ๏ธ Getting Started #

final assetsAudioPlayer = AssetsAudioPlayer();

You can also play network songs from url

final assetsAudioPlayer = AssetsAudioPlayer();

try {
} 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 {
} catch (t) {
    //stream unreachable

And play songs from file

//create a new player
final assetsAudioPlayer = AssetsAudioPlayer();

for file uri, please look at

assetsAudioPlayer.pause(); to);
assetsAudioPlayer.seekBy(Duration by);
assetsAudioPlayer.forwardRewind(double speed);
//if positive, forward, if negative, rewind

Notifications #



on iOS, it will use MPNowPlayingInfoCenter

  1. Add metas inside your audio
final audio = Audio("/assets/audio/country.mp3", 
    metas: Metas(
            title:  "Country",
            artist: "Florent Champigny",
            album: "CountryAlbum",
            image: MetasImage.asset("assets/images/country.jpg"), //can be
  1. open with showNotification: true, showNotification: true)

Custom notification #

Custom icon (android only)

By ResourceName #

Make sur you added those icons inside your android/res/drawable !!! not on flutter assets !!!!

        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)

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns: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 #

  1. Add your icon into your android's res folder (android/app/src/main/res)

  2. Reference this icon into your AndroidManifest (android/app/src/main/AndroidManifest.xml)


You can also change actions icons


Custom actions #

You can enable/disable a notification action

   showNotification: true,
   notificationSettings: NotificationSettings(
       prevEnabled: false, //disable the previous button
       //and have a custom next action (will disable the default action)
       customNextAction: (player) {


Update audio's metas / notification content #

After your audio creation, just call

       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
         //my new image url

Bluetooth Actions #

You have to enable notification to make them work

Available remote commands :

  • Play / Pause
  • Next
  • Prev
  • Stop

HeadPhone Strategy #

(Only for Android for now)

while opening a song/playlist, add a strategy
  headPhoneStrategy: HeadPhoneStrategy.pauseOnUnplug,
  //headPhoneStrategy: HeadPhoneStrategy.none, //default
  //headPhoneStrategy: HeadPhoneStrategy.pauseOnUnplugPlayOnPlug,

If you want to make it work on bluetooth too, you'll have to add the BLUETOOTH permission inside your AndroidManifest.xml

<uses-permission android:name="android.permission.BLUETOOTH" />

โ›“ Play in parallel / simultaneously #

You can create new AssetsAudioPlayer using AssetsAudioPlayer.newPlayer(), which will play songs in a different native Media Player

This will enable to play two songs simultaneously

You can have as many player as you want !

///play 3 songs in parallel

//another way, with create, open, play & dispose the player on finish

Each player has an unique generated id, you can retrieve or create them manually using

final player = AssetsAudioPlayer.withId(id: "MY_UNIQUE_ID");

๐Ÿ—„๏ธ Playlist #
    audios: [
  loopMode: LoopMode.playlist //loop the full playlist

Audio Widget #

If you want a more flutter way to play audio, try the AudioWidget !


//inside a stateful widget

bool _play = false;

Widget build(BuildContext context) {
  return Audio.assets(
     path: "assets/audios/country.mp3",
     play: _play,
     child: RaisedButton(
           child: Text(
               _play ? "pause" : "play",
           onPressed: () {
               setState(() {
                 _play = !_play;
      onReadyToPlay: (duration) {
      onPositionChanged: (current, duration) {

How to ๐Ÿ›‘ stop ๐Ÿ›‘ the AudioWidget ?

Just remove the Audio from the tree ! Or simply keep play: false

๐ŸŽง Listeners #

All listeners exposes Streams Using RxDart, AssetsAudioPlayer exposes some listeners as ValueObservable (Observable that provides synchronous access to the last emitted item);

๐ŸŽต Current song #

//The current playing audio, filled with the total song duration
assetsAudioPlayer.current //ValueObservable<PlayingAudio>

//Retrieve directly the current played asset
final PlayingAudio playing = assetsAudioPlayer.current.value;

//Listen to the current playing song
    final asset = playingAudio.assetAudio;
    final songDuration = playingAudio.duration;

โŒ› Current song duration #

//Listen to the current playing song
final duration = assetsAudioPlayer.current.value.duration;

โณ Current position (in seconds) #

assetsAudioPlayer.currentPosition //ValueObservable<Duration>

//retrieve directly the current song position
final Duration position = assetsAudioPlayer.currentPosition.value;

return StreamBuilder(
    stream: assetsAudioPlayer.currentPosition,
    builder: (context, asyncSnapshot) {
        final Duration duration =;
        return Text(duration.toString());  

or use a PlayerBuilder !

     player: _assetsAudioPlayer,
     builder: (context, duration) {
       return Text(duration.toString());  

or Player Builder Extension

     builder: (context, duration) {
       return Text(duration.toString());  

โ–ถ IsPlaying #

boolean observable representing the current mediaplayer playing state

assetsAudioPlayer.isPlaying // ValueObservable<bool>

//retrieve directly the current player state
final bool playing = assetsAudioPlayer.isPlaying.value;

//will follow the AssetsAudioPlayer playing state
return StreamBuilder(
    stream: assetsAudioPlayer.isPlaying,
    builder: (context, asyncSnapshot) {
        final bool isPlaying =;
        return Text(isPlaying ? "Pause" : "Play");  

or use a PlayerBuilder !

     player: _assetsAudioPlayer,
     builder: (context, isPlaying) {
       return Text(isPlaying ? "Pause" : "Play");  

or Player Builder Extension

     builder: (context, isPlaying) {
       return Text(isPlaying ? "Pause" : "Play");  

๐Ÿ”Š Volume #

Change the volume (between 0.0 & 1.0)


The media player can follow the system "volume mode" (vibrate, muted, normal) Simply set the respectSilentMode optional parameter as true, respectSilentMode: true);

Listen the volume

return StreamBuilder(
    stream: assetsAudioPlayer.volume,
    builder: (context, asyncSnapshot) {
        final double volume =;
        return Text("volume : $volume");  

or use a PlayerBuilder !

     player: _assetsAudioPlayer,
     builder: (context, volume) {
       return Text("volume : $volume");

โœ‹ Finished #

Called when the current song has finished to play,

it gives the Playing audio that just finished

assetsAudioPlayer.playlistAudioFinished //ValueObservable<Playing>

assetsAudioPlayer.playlistAudioFinished.listen((Playing playing){

Called when the complete playlist has finished to play

assetsAudioPlayer.playlistFinished //ValueObservable<bool>


๐Ÿ” Looping #

final LoopMode loopMode = assetsAudioPlayer.loop; 
// possible values
// LoopMode.none : not looping
// LoopMode.single : looping a single audio
// LoopMode.playlist : looping the fyll playlist


    //listen to loop

assetsAudioPlayer.toggleLoop(); //toggle the value of looping

Error Handling #

By default, on playing error, it stop the audio

BUT you can add a custom behavior

_player.onErrorDo = (handler){

Open another audio

_player.onErrorDo = (handler){;

Try to open again on same position

_player.onErrorDo = (handler){
        startIndex: handler.playlistIndex
      seek: handler.currentPosition

Network Policies (android/iOS/macOS) #

Android only allow HTTPS calls, you will have an error if you're using HTTP, don't forget to add INTERNET permission and seet usesCleartextTraffic="true" in your AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />

iOS only allow HTTPS calls, you will have an error if you're using HTTP, don't forget to edit your info.plist and set NSAppTransportSecurity to NSAllowsArbitraryLoads


To enable http calls on macOs, you have to add input/output calls capabilities into info.plist


and in your




Complete Runner/DebugProfile.entitlements

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

๐ŸŽถ Musics #

All musics used in the samples came from

2.0.7+89 #

  • Added Android HeadPhoneStrategy
  • Fix local path file uri (android)

2.0.6+7 #

  • Cache now use http instead of dio
  • Added live tag on notification for LiveStream play (ios)
  • Added audio session id (android only)

2.0.5+7 #

  • Added custom error handling (beta)
  • Dispose is now a future
  • Fixed playlist insert / replace

2.0.5 #

  • Added Cache management (beta), with, cached: true)

2.0.4+2 #

  • Added HLS, Dash, SmoothStream support on Android
  • Added laylist.replaceAt method

2.0.3+6 #

  • ExoPlayer network now set allowCrossProtocolRedirect=true by default
  • Fixed notification hide on livestream pause (android)
  • Added custom icons for android from drawable names
  • Fixed notification texts on Samsung devices

2.0.3+1 #

  • Added custom notification icons for Android (in AndroidManifest.xml)
  • Fixed seek and seekBy not working on the web
  • PlayList.startIndex is now mutable
  • Stop player then call play reopen it at playlist.startIndex
  • Increased buffer size on android/exoplayer
  • Added keepLoopMode on prev/next

2.0.2 #

  • Breaking change : loop boolean now enumerate 3 values : none, single and playlist

2.0.1+9 #

  • Added .showNotification = true/false to hide dynamically displayed notification
  • Added custom action on notif click(android)
  • Added isBuffering to RealtimePlayingInfos
  • Added AssetsAudioPlayerGroup (beta)
  • Added Headers in & Audio.liveStream

2.0.1 #

  • Added .playerState (play/pause/stop)
  • Stop now ping finish listeners

2.0.0+6 #

  • Added MacOS support
  • Fixed gapeless loop (single audio)
  • Fixed audio file notification

1.7.0 #

  • Fixed bluetooth on android on some devices
  • Fallback to android native MediaPlayer if exoplayer can't read the file
  • Added audio.updateMetas to update notification content after creation
  • Android Seekbar notification is now optional
  • Android usable notification Seekbar
  • Added stop custom notification action

1.6.3 #

  • Custom notification icon (android)
  • Custom notification actions
  • Fixed notification close on android
  • Fixed android auto-focus
  • Added playInBackground mode
  • Added shuffle

1.6.1 #

  • Playlist is now mutable, we can add audios after creation
  • renamed ReadingPlaylist get playlist to ReadingPlaylist get readingPlaylist
  • added Playlist get playlist

1.6.0+4 #

  • Fixed playlist issue on android
  • Fixed issue on bluetooth android play/pause
  • Fixed PlayerBuilder currentPosition
  • Added extra map into audio

1.6.0 #

  • Added some checks on swift code
  • Fixed totalDuration or liveStream
  • Fixed ios notifications
  • Added bluetooth headset actions (play/pause/next/prev/stop)

1.5.0 #

  • Added Audio.liveStream(url)
  • Fixed notification image from assets on android
  • Fixed android notification actions on playlist
  • Added AudioWidget

1.4.7 #

  • added package on assets audios (& notif images)
  • all methods return Future
  • open can throw an exception if the url is not found

1.4.6+1 #

  • fixed android notifications actions
  • refactored package, added src/ and package keyword
  • added player_builders

1.4.5 #

  • fixed implementation of local file play on iOS

1.4.4 #

  • Added notifications on android

1.4+3+6 #

  • Beta fix for audio focus

1.4+3+5 #

  • Beta implementation of local file play on iOS

1.4.3+4 #

  • Moved to last flutter version >=1.12.13+hotfix.6
  • Implemented new android FlutterPlugin
  • Stop all players while getting a phone call
  • Added playspeed as optional parameter on on open()

1.4.2+1 #

  • Moved to android ExoPlayer
  • Added playSpeed (beta)
  • Added forwardRewind (beta)
  • Added seekBy

1.4.0+1 #

  • Bump gradle versions : wrapper=(5.4.1-all) build:gradle=(3.5.3)

1.4.0 #

  • Added respectSilentMode as open optional argument
  • Added showNotification on iOS to map with MPNowPlayingInfoCenter (default: false)
  • Added metas on audios (title, artist, ...) for notifications
  • Use new plugin build format for iOS

1.3.9 #

  • Empty constructor now create a new player
  • Added factory AssetsAudioPlayer.withId()
  • Added playAndForget witch create, open, play & dispose the player on finish
  • Added AssetsAudioPlayer.allPlayers() witch returns a map of all players
  • Reworked the android player

1.3.8+1 #

  • Added seek as optional parameter on open method

1.3.8 #

  • Fully rebased the web support on html.AudioElement (instead of howler)
  • Fully rebases the ios support on AvPlayer (instead of AvAudioPlayer)
  • Added support for network audios with .open( on Android/ios/web

1.3.7+1 #

  • Added RealtimePlayingInfos stream

1.3.6+1 #

  • Added volume as optional parameter on open()

1.3.6 #

  • Extracted web support to assets_audio_player_web: 1.3.6

1.3.5+1 #

  • Volume does not reset anymore on looping audios

1.3.4 #

  • Fixed player on Android

1.3.3 #

  • Fixed build on Android & iOS

1.3.2 #

1.3.1+2 #

  • Upgraded RxDart dependency
  • fixed lint issues
  • lowerCamelCase AssetsAudioPlayer volumes consts

1.3.1 #

  • Fixed build on iOS

1.3.0 #

  • Added web support, works only on debug mode

1.2.8 #

  • Added constructors
  • AssetsAudioPlayer.newPlayer
  • AssetsAudioPlayer(id: "PLAYER_ID")

to create new players and play multiples songs in parallel

the default constructor AssetsAudioPlayer() still works as usual

1.2.7 #

  • Added "volume" property (listen/set)

1.2.6 #

  • Added an "autoPlay" optional attribute to open methods

1.2.5 #

  • Compatible with Swift 5

1.2.4 #

  • Added playlist

1.2.3 #

  • Added playlist (beta)

1.2.1 #

  • Added looping setter/getter

1.2.0 #

  • Upgraded RxDart to 0.23.1
  • Fixed assets playing on iOS
  • Fixed playing location on Android

0.0.1 #

  • initial release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  assets_audio_player_web: ^2.0.7+9

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:assets_audio_player_web/assets_audio_player_web.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux


  • package:assets_audio_player_web/assets_audio_player_web.dart that declares support for platforms: android, ios, macos, web

Package does not support Flutter platform windows


  • package:assets_audio_player_web/assets_audio_player_web.dart that declares support for platforms: android, ios, macos, web

Package not compatible with SDK dart


  • assets_audio_player_web that is a package requiring null.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and assets_audio_player_web.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
flutter 0.0.0
flutter_web_plugins 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies