Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications

Overview

🎧 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

flutter:
  assets:
    - assets/audios/
AssetsAudioPlayer.newPlayer().open(
    Audio("assets/audios/song1.mp3"),
    autoPlay: true,
    showNotification: true,
);

sample1 sample1

📥 Import

dependencies:
  assets_audio_player: ^3.0.3+1
  
or

assets_audio_player:
git:
url: https://github.com/florent37/Flutter-AssetsAudioPlayer.git
ref: master

ref can be latest commit id. 

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 ko-fi.com

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
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

notification

notification

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 MetasImage.network
          ),
   );
  1. open with showNotification: true
_player.open(audio, 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 !!!!

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

  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)

<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

HeadPhone Strategy

(Only for Android for now)

while opening a song/playlist, add a strategy

assetsAudioPlayer.open(
   ...
  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
AssetsAudioPlayer.newPlayer().open(
    Audio("assets/audios/song1.mp3")
);
AssetsAudioPlayer.newPlayer().open(
    Audio("assets/audios/song2.mp3")
);

//another way, with create, open, play & dispose the player on finish
AssetsAudioPlayer.playAndForget(
    Audio("assets/audios/song3.mp3")
);

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

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

🗄️ Playlist

assetsAudioPlayer.open(
  Playlist(
    audios: [
      Audio("assets/audios/song1.mp3"),
      Audio("assets/audios/song2.mp3")
    ]
  ),
  loopMode: LoopMode.playlist //loop the full playlist
);

assetsAudioPlayer.next();
assetsAudioPlayer.prev();
assetsAudioPlayer.playlistPlayAtIndex(1);

Audio Widget

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

sample

//inside a stateful widget

bool _play = false;

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

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
assetsAudioPlayer.current.listen((playingAudio){
    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 = asyncSnapshot.data;
        return Text(duration.toString());  
    }),

or use a PlayerBuilder !

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

or Player Builder Extension

_assetsAudioPlayer.builderCurrentPosition(
     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 = asyncSnapshot.data;
        return Text(isPlaying ? "Pause" : "Play");  
    }),

or use a PlayerBuilder !

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

or Player Builder Extension

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

🔊 Volume

Change the volume (between 0.0 & 1.0)

assetsAudioPlayer.setVolume(0.5);

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

_player.open(PLAYABLE, respectSilentMode: true);

https://developer.android.com/reference/android/media/AudioManager.html?hl=fr#getRingerMode()

https://developer.apple.com/documentation/avfoundation/avaudiosessioncategorysoloambient

Listen the volume

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

or use a PlayerBuilder !

PlayerBuilder.volume(
     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>

assetsAudioPlayer.playlistFinished.listen((finished){
    
})

🔁 Looping

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

assetsAudioPlayer.setLoopMode(LoopMode.single);

assetsAudioPlayer.loopMode.listen((loopMode){
    //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){
  handler.player.stop();
};

Open another audio

_player.onErrorDo = (handler){
  handler.player.open(ANOTHER_AUDIO);
};

Try to open again on same position

_player.onErrorDo = (handler){
  handler.player.open(
      handler.playlist.copyWith(
        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" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

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

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

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

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>
<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
    <string>fetch</string>
</array>
<key>com.apple.security.network.client</key>
<true/>

and in your

Runner/DebugProfile.entitlements

add

<key>com.apple.security.network.client</key>
<true/>

Complete Runner/DebugProfile.entitlements

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.app-sandbox</key>
	<true/>
	<key>com.apple.security.cs.allow-jit</key>
	<true/>
	<key>com.apple.security.network.server</key>
	<true/>
	<key>com.apple.security.network.client</key>
	<true/>
</dict>
</plist>

🎶 Musics

All musics used in the samples came from https://www.freemusicarchive.org/

Comments
  • App entirely crashes on assets_audio_player: ^1.5.0+3 version IOS when open playlist

    App entirely crashes on assets_audio_player: ^1.5.0+3 version IOS when open playlist

    App crashes and writes lost connection to device in IOS Real Device 13.3 IOS version. I tried put autoStart to false and play atIndex. Nothing has changed it still just crashes.

    bug Working on it waiting for user test 
    opened by Azandowski 218
  • MediaButtonReceive IllegalStateException

    MediaButtonReceive IllegalStateException

    Flutter Version

    Flutter 1.20.1 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 2ae34518b8 (12 days ago) • 2020-08-05 19:53:19 -0700
    Engine • revision c8e3b94853
    Tools • Dart 2.9.0
    
    assets_audio_player:
    dependency: "direct main"
    description:
        name: assets_audio_player
        url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.9+2"
    

    Platform (Android / iOS / web) + version

    Platform : Android

    Describe the bug

    java.lang.RuntimeException: 
      at android.app.ActivityThread.handleReceiver (ActivityThread.java:3612)
      at android.app.ActivityThread.access$1300 (ActivityThread.java:237)
      at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1796)
      at android.os.Handler.dispatchMessage (Handler.java:106)
      at android.os.Looper.loop (Looper.java:214)
      at android.app.ActivityThread.main (ActivityThread.java:7050)
      at java.lang.reflect.Method.invoke (Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
    Caused by: java.lang.IllegalStateException: 
      at androidx.media.session.MediaButtonReceiver.onReceive (MediaButtonReceiver.java:74)
      at android.app.ActivityThread.handleReceiver (ActivityThread.java:3603)
      at android.app.ActivityThread.access$1300 (ActivityThread.java:237)
      at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1796)
      at android.os.Handler.dispatchMessage (Handler.java:106)
      at android.os.Looper.loop (Looper.java:214)
      at android.app.ActivityThread.main (ActivityThread.java:7050)
      at java.lang.reflect.Method.invoke (Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
    
    bug 
    opened by markst 63
  • error on compile :assets_audio_player:compileDebugKotlin'.

    error on compile :assets_audio_player:compileDebugKotlin'.

    Hi, I can not compile my project because the issue below, someone could help me please?

    e: C:\Users\rocha\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\assets_audio_player-2.0.13+1\android\src\main\kotlin\com\github\florent37\assets_audio_player\Player.kt: (542, 5): 'handleMessage' overrides nothing
    e: C:\Users\rocha\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\assets_audio_player-2.0.13+1\android\src\main\kotlin\com\github\florent37\assets_audio_player\Player.kt: (543, 29): Type mismatch: inferred type is Message? but Message was expected
    e: C:\Users\rocha\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\assets_audio_player-2.0.13+1\android\src\main\kotlin\com\github\florent37\assets_audio_player\notification\NotificationActionReceiver.kt: (12, 85): Type mismatch: inferred type is String? but String was expected
    e: C:\Users\rocha\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\assets_audio_player-2.0.13+1\android\src\main\kotlin\com\github\florent37\assets_audio_player\notification\NotificationActionReceiver.kt: (30, 39): Type mismatch: inferred type is Intent? but Intent was expected
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':assets_audio_player:compileDebugKotlin'.
    > Compilation error. See log for more details
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    

    BUILD FAILED in 26s Exception: Gradle task assembleDebug failed with exit code 1

    assets_audio_player: ^2.0.13+1

    Flutter is already up to date on channel stable
    Flutter 1.22.3 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 8874f21e79 (13 days ago) • 2020-10-29 14:14:35 -0700
    Engine • revision a1440ca392
    Tools • Dart 2.10.3
    
    bug 
    opened by robertoltrocha 40
  • Single notification bar for multiple player & navigation to specific player page when user clicks in notification.

    Single notification bar for multiple player & navigation to specific player page when user clicks in notification.

    Describe the feature you'd like

    Now all the music instance have separate notification bar but if user want to control all the instance from one place, there is no option for that. There should be an single notification bar for playing multiple music at once so that user can stop, pause and play all the instance of player at once.

    and most of the music player notification bar give option to navigate to the player page when the click on it would be nice to see this feature in this package. something like this. https://play.google.com/store/apps/details?id=ipnossoft.rma.free

    new feature Working on it waiting for user test 
    opened by Timus23 36
  • [Android] Is there a way to resume audio (like Spotify) after my player is done?

    [Android] Is there a way to resume audio (like Spotify) after my player is done?

    I have an app that has to stop the current music in a interval of 15 minutes, play an audio and (when the player is done) resume the native player after finishing playback. My app is working except for this feature.

    Working on it help wanted android 
    opened by savioPimenta 34
  • [Android] [HLS] Add hls support (Got error message when playing live stream format

    [Android] [HLS] Add hls support (Got error message when playing live stream format "m3u8")

    Flutter Version

    My version : 1.17.3

    Lib Version

    My version : 2.0.3+6

    Platform (Android / iOS / web) + version

    Platform : Android 29

    Describe the bug

    The example code can play the stream, but get error message when playing live stream format "m3u8".

    error message below :

    I/ExoPlayerImpl( 9534): Init 7c4b802 [ExoPlayerLib/2.11.4] [generic_x86_64, Android SDK built for x86_64, Google, 29] E/ExoPlayerImplInternal( 9534): Source error E/ExoPlayerImplInternal( 9534): com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, OggExtractor, PsExtractor, WavExtractor, AmrExtractor, Ac4Extractor, FlacExtractor) could read the stream. E/ExoPlayerImplInternal( 9534): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractorHolder.selectExtractor(ProgressiveMediaPeriod.java:1090) E/ExoPlayerImplInternal( 9534): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:969) E/ExoPlayerImplInternal( 9534): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:391) E/ExoPlayerImplInternal( 9534): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/ExoPlayerImplInternal( 9534): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/ExoPlayerImplInternal( 9534): at java.lang.Thread.run(Thread.java:919) I/ExoPlayerImpl( 9534): Release 7c4b802 [ExoPlayerLib/2.11.4] [generic_x86_64, Android SDK built for x86_64, Google, 29] [goog.exo.core] V/MediaPlayer( 9534): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false V/MediaPlayer( 9534): cleanDrmObj: mDrmObj=null mDrmSessionId=null V/MediaHTTPService( 9534): MediaHTTPService(android.media.MediaHTTPService@a8cff6f): Cookies: null V/MediaHTTPService( 9534): makeHTTPConnection: CookieHandler (java.net.CookieManager@40ab8a5) exists. V/MediaHTTPService( 9534): makeHTTPConnection(android.media.MediaHTTPService@a8cff6f): cookieHandler: java.net.CookieManager@40ab8a5 Cookies: null W/MediaPlayerNative( 9534): info/warning (801, 0) V/MediaPlayer( 9534): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false V/MediaPlayer( 9534): cleanDrmObj: mDrmObj=null mDrmSessionId=null W/MediaPlayer( 9534): mediaplayer went away with unhandled events W/MediaPlayer( 9534): mediaplayer went away with unhandled events

    Small code to reproduce Just modify the 2.0.3+6 's example code "main_livestream.dart" with the URL below :

    "https://18843.live.streamtheworld.com/WBBRAMAAC48/HLS/playlist.m3u8",

    bug new feature android 
    opened by erickcchoi 34
  • Open method creates new AssetsAudioPlayer

    Open method creates new AssetsAudioPlayer

    Flutter Version

    My version : 1.18.0-10.0.pre

    Lib Version

    My version : ^2.0.5

    Platform (Android / iOS / web) + version

    Platform : Android 10

    I want to start off by saying, thank you for this amazing library, I've been looking for something like this for months now.

    Bug When I have a list of songs on ListTiles with an onTap callback to the .open() function. If the feature is misused by tapping on lots of them in a short amount of time, new Audio Players are spawned playing songs in parallel which is not what I want to happen. Is there a way to stop new AudioPlayers from being created? Is it something with the open function not being given enough time to respond when tapped in a short period of time?

    Things I've Tried but didn't help -- using Future.delay() before calling .open() --monitoring the map of audio players with AssetsAudioPlayer.allPlayers() and disposing of new instances of AudioPlayers

    Any help is appreciated!

    Small code to reproduce

    import 'package:assets_audio_player/assets_audio_player.dart';
    import 'package:flutter/material.dart';
    
    //sketch up code to show bug in a list 
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatefulWidget {
      
      const MyApp({Key key, this.playlist}) : super(key: key);
      @override
      _MyAppState createState() => _MyAppState();
    }
    
    class _MyAppState extends State {
      
      final AssetsAudioPlayer _assetsAudioPlayer = AssetsAudioPlayer();
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: List.builder(
              itemCount:widget.playlist.audios.length,
              itemBuilder:(BuildContext context, int index){
                return ListTile(
                   title: Text("open"),
                    onTap: () {
                      //open code here
                   _assetsAudioPlayer.open(
                      widget.playlist,
                   )
                }
              ),
            ),
          ),
        );
      }
    }
    
    bug 
    opened by johnny-stevie 31
  • Need flutter 2.0 support  (Null safety)

    Need flutter 2.0 support (Null safety)

    Need flutter 2.0 support (Null safety) My Flutter version is: 2.0.1 • channel stable

    I got the following error:

    Because assets_audio_player >=2.0.14 depends on path_provider ^1.6.27 which depends on path_provider_windows ^0.0.4, assets_audio_player >=2.0.14 requires path_provider_windows ^0.0.4. And because shared_preferences_windows 2.0.0 depends on path_provider_windows ^2.0.0 and no versions of shared_preferences_windows match >2.0.0 <3.0.0, assets_audio_player >=2.0.14 is incompatible with shared_preferences_windows ^2.0.0. And because shared_preferences 2.0.3 depends on shared_preferences_windows ^2.0.0 and no versions of shared_preferences match >2.0.3 <3.0.0, assets_audio_player >=2.0.14 is incompatible with shared_preferences ^2.0.3.

    bug 
    opened by pmathulan 26
  • [New feature] Update current playlist.

    [New feature] Update current playlist.

    It would be nice to have the possibility to update the current playlist (which was set via player.open(playlist)).

    Why?

    In my case when I create a playlist I am checking if audio was cached by me previously, then I add it as a local file. If no - then add network audio and when the user plays it - I am caching it. When caching is done - I would like to update playlist (replace network audio with local), so in case user would like to hear that song one more time, he/she will not need internet connection anymore.

    - add(audio)
    - addAt(audio, index)
    - addAll(List audios)
    
    - remove(audio)
    - removeAt(audio, index)
    - removeAll(List audios)
    
    - contains(audio)
    
    new feature Working on it 
    opened by pro100svitlo 24
  • The plugin is not calling dispose when doing Hot restart in debug mode.

    The plugin is not calling dispose when doing Hot restart in debug mode.

    Flutter Version

    My version :

    Flutter 1.19.0-2.0.pre.143 • channel master • https://github.com/flutter/flutter.git
    Framework • revision 9d58a87066 (4 days ago) • 2020-05-22 22:37:01 -0700
    Engine • revision 9ce1e5c5c7
    Tools • Dart 2.9.0 (build 2.9.0-10.0.dev 7706afbcf5)
    

    Lib Version

    My version : 1.4.6

    Platform (Android / iOS / web) + version

    Platform : Android / iOS

    Describe the bug

    I'm wondering if this is a bug or a feature but the plugin is not disposing when app goes on background or for example when using a simulator and pressing shift + R to perform a hot restart. I know it's kind of a feature if you set the notification and you might want this to play in background but I believe there should be at least an option to avoid this. Also on iOS simulator when moving the app in background it starts to make a scary weird metallic sound.

    bug 
    opened by dbertella 24
  • compile errors

    compile errors

    Flutter Version 1.7.1 My version : ^1.6.2+2 Lib Version

    My version :

    Platform (Android / iOS / web) + version

    Platform : ios Describe the bug 7 warnings generated. /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:134:44: error: type 'AVAudioSession.Category' (aka 'NSString') has no member 'playback' return AVAudioSession.Category.playback ~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:136:44: error: type 'AVAudioSession.Category' (aka 'NSString') has no member 'soloAmbient' return AVAudioSession.Category.soloAmbient ~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:138:44: error: type 'AVAudioSession.Category' (aka 'NSString') has no member 'playback' return AVAudioSession.Category.playback ~~~~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:185:66: error: type 'String' has no member 'playback' try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) ~^~~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:185:83: error: type 'String' has no member 'default' try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: []) ~^~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:188:66: error: type 'String' has no member 'playback' try AVAudioSession.sharedInstance().setCategory(.playback, options: []) ~^~~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:353:44: error: type 'AVAudioSession.Mode' (aka 'NSString') has no member 'default' let mode = AVAudioSession.Mode.default ~~~~~~~~~~~~~~~~~~~ ^~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:356:42: error: value of type 'AVAudioSession.Category' (aka 'NSString') has no member 'rawValue' print("category " + category.rawValue); ~~~~~~~~ ^~~~~~~~ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:368:65: error: 'AVAudioSession.Category' (aka 'NSString') is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert? try AVAudioSession.sharedInstance().setCategory(category, options: .mixWithOthers) ^ as String /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:450:11: warning: 'catch' block is unreachable because no errors are thrown in 'do' block } catch let error { ^ /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:466:47: error: extraneous argument label 'preferredTimescale:' in call let targetTime = CMTimeMakeWithSeconds(Double(to), preferredTimescale: 1) ^ ~~~~~~~~~~~~~~~~~~~~

    /Users/emery/.pub-cache/hosted/pub.flutter-io.cn/assets_audio_player-1.6.2+2/ios/Classes/Music.swift:512:38: error: 'zero' has been renamed to 'kCMTimeZero'
            self.player?.seek(to: CMTime.zero)
                                         ^~~~
                                         kCMTimeZero
    CoreMedia.CMTime:16:23: note: 'zero' was introduced in Swift 4.2
        public static let zero: CMTime
    

    A clear and concise description of what the bug is.

    bug 
    opened by ZMNOTZ 23
  • Audio cuts when using the device's Phone UI

    Audio cuts when using the device's Phone UI

    Hello. I'm not sure if this counts as a bug or a feature request, though I'll try to keep it brief.

    I'm using Callkeep to show incoming and outgoing calls for my app on Android. However, I would like to play a sound while an outgoing call is ringing. I tried using AssetsAudioPlayer for this purpose, and while it works when initiating the call, the moment the Phone UI shows up, the audio stops altogether. If I don't manually or programatically stop the audio once the call ends, it will still be playing, as if the device simply silenced the audio and not outright stop it.

    Is there a way to keep the audio's volume up all the while? I'm assuming this has something to do with the way the device prioritizes tasks, but I can't say for sure.

    opened by amilcar-uptech 0
  • @kalismeras61  facing same issue with the **android** and **ios** please reopen this issue.and i have also followed all the things which are mentioned in the document. still background music is getting stopped when we play some sound by asset audio player. In video player we have this kind of option to mix sound with other playing audio which are playing but in audio player we can not do this

    @kalismeras61 facing same issue with the **android** and **ios** please reopen this issue.and i have also followed all the things which are mentioned in the document. still background music is getting stopped when we play some sound by asset audio player. In video player we have this kind of option to mix sound with other playing audio which are playing but in audio player we can not do this

        @kalismeras61  facing same issue with the **android** and **ios** please reopen this issue.and i have also followed all the things which are mentioned in the document. still background music is getting stopped when we play some sound by asset audio player. In video player we have this kind of option to mix sound with other playing audio which are playing but in audio player we can not do this
    
    Screenshot 2022-10-01 at 3 17 13 PM

    Originally posted by @BlackStriker99 in https://github.com/florent37/Flutter-AssetsAudioPlayer/issues/423#issuecomment-1264308739

    opened by BlackStriker99 2
  • removeAudio method is not working AssetsAudioPlayerGroup

    removeAudio method is not working AssetsAudioPlayerGroup

    Flutter Version

    My version : 3.3.8

    Lib Version

    My version : 3.0.6

    Platform (Android )

    I have a list of music added into a group and i want to remove a specific music by its path using removeAudio method. but its is not working.

    AssetsAudioPlayerGroup assetsAudioPlayerGroup = AssetsAudioPlayerGroup(
          updateNotification: (group, listOfAudios) async {
            return PlayerGroupMetas(
              image: const MetasImage(
                path: 'assets/images/fire.png',
                type: ImageType.asset,
              ),
            );
          },
        );
    
    //adding music
     await assetsAudioPlayerGroup.add(
                                    Audio(
                                      universalProvider
                                          .getList[index].musicPath,
                                    ),
                                  );
    //removing music 
    await assetsAudioPlayerGroup.removeAudio(Audio(
                                    universalProvider
                                        .getList[index].musicPath,
                                  ));
    
    
    but it is not worrking. Please help
    
    
    bug 
    opened by adiShinwari 0
  • Notification always appears when I swipe down the notification screen on iOS

    Notification always appears when I swipe down the notification screen on iOS

    Flutter Version

    My version : 3.3.0

    Lib Version

    My version : 3.0.6

    Platform (Android / iOS / web) + version

    Platform : IOS

    Describe the bug ezgif com-gif-maker

    I'm playing a sound from assets with repeat (game background sound). Notification always appears when I swipe down the notification screen on iOS even though I have called pause() and set "showNotification: false". I want the notification to never appear when my app plays sound. Can you tell me the solution to solve this problem? Thank you so much!

    Small code to reproduce

          assetsAudioPlayer.open(Audio(_backgroundMusicPath), 
            volume: 1.0, 
            loopMode: LoopMode.single,
            showNotification: false,
          );
    
    bug 
    opened by trantruongan136 0
  • shuffle is not working properly

    shuffle is not working properly

    @florent37 shuffle is not working when i unshuffle audios it doesn't play the next audio rather it doing shuffle playlist. I hope this will be fix soon. Thanks for your time and support.

    bug 
    opened by abhaysharma309 0
  • MetasImages.file or MetasImages.asset doesn't work

    MetasImages.file or MetasImages.asset doesn't work

    Hi dear Developer,

    On the last version assets_audio_player: ^3.0.6

    I think there is bug in loading music's cover in iOS music notification,

    await player.open( Audio.file(music.path, metas: Metas( title: music.title ?? '', artist: music.artist ?? '', album: music.album ?? '', image: MetasImage.file('${music.path}.jpg'), onImageLoadFail: const MetasImage.network( 'https://songdewnetwork.com/sgmedia/assets/images/default-album-art.png'))), showNotification: true, notificationSettings: const NotificationSettings( playPauseEnabled: true, nextEnabled: true, seekBarEnabled: true, prevEnabled: true, stopEnabled: true, ));

    Here is my code part, MetasImage.file('${music.path}.jpg'), doesn't load the music's cover, even onImageLoadFail doesn't load default cover image.

    iOS version: 15

    Cheers!

    bug 
    opened by sina-moradbakhti 0
Just_audio: a feature-rich audio player for Android, iOS, macOS and web

just_audio just_audio is a feature-rich audio player for Android, iOS, macOS and web. Mixing and matching audio plugins The flutter plugin ecosystem c

Ensar Yusuf Yılmaz 2 Jun 28, 2022
A flutter based music player for subsonic compatible music servers.

subsound A subsonic music player. Screenshots Release todo fix random breakage of player sometimes. seems like onStart is not working after background

Eivind Siqveland Larsen 26 Oct 6, 2022
Playify is a Flutter plugin for play/pause/seek songs, fetching music metadata, and browsing music library.

Playify Playify is a Flutter plugin for play/pause/seek songs, fetching music metadata, and browsing music library. Playify was built using iOS's Medi

Ibrahim Berat Kaya 32 Dec 14, 2022
Flutter-Music-Player - A simple music player app that let you play mp3 songs with some customization feature with a rich user interface

Flutter-Music-Player - A simple music player app that let you play mp3 songs with some customization feature with a rich user interface

Ashirbad Swain 6 Jan 4, 2023
Apps For streaming audio via url (Android, iOS & Web ). Developed with Dart & Flutter ❤

Flutter Sleep App (Dicoding Submission : Learn to Make Flutter Apps for Beginners) Stream Great collection of high-definition sounds that can be mixed

Utrodus Said Al Baqi 13 Nov 29, 2022
A simple audio room using WebRTC P2P mesh network.

P2P Audio Room A simple audio room using peer to peer technology with WebRTC mesh network. Download the app from here Here I have used:- flutter_webrt

Krishnendu Bera 9 Oct 28, 2022
Audio Recorder Jordan AlcarazAudio Recorder [156⭐] - Record audio and store it locally by Jordan Alcaraz.

Audio recorder Record audio and store it locally Usage To use this plugin, add audio_recorder as a dependency in your pubspec.yaml file. Android Make

Jordan Alcaraz 172 Jan 4, 2023
WaVe - an audio streaming platform which gives the best user experience without any compromise in the audio quality

WaVe is an audio streaming platform which gives the best user experience without any compromise in the audio quality, and there is even space for the users to explore their creativity. And makes it more efficient with the AI features.

OmarFayadhd 1 May 31, 2022
A cross-platform mobile app that helps you to generate transcripts either from a voice recording or by uploading an audio file

A cross-platform mobile app that helps you to generate transcripts either from a voice recording or by uploading an audio file

Souvik Biswas 26 Dec 18, 2022
A Flutter music player to play songs (mp3).

?? ?? Flutter Music A Flutter music player to play songs (mp3). Please star ⭐ the repo if you like what you see ?? . ?? Requirements Any Operating Sys

null 109 Dec 16, 2022
WazPlay is just a music app written in flutter and service to download song and play it.

wazplay Introduction WazPlay is just a music app written in flutter and service to download song and play it. WazPlay is the first product for Waz and

Zaw Lin Tun 4 Dec 8, 2022
Music Player app made with Just audio library and Local database Hive.

Music Player app made with Just audio library and Local database Hive. Find the free and Royelty music with Happy Rock application. The app contains information about singers and you can make your own playlist with Songs.Happy rock App's features are same as the real music app like spotify, amazon music etc.

Ansh rathod 17 Dec 22, 2022
A Flutter package for both android and iOS which provides Audio recorder

social_media_recorder A Flutter package for both android and iOS which provides

subhikhalifeh 16 Dec 29, 2022
Audio classification Tflite package for flutter (iOS & Android).

Audio classification Tflite package for flutter (iOS & Android). Can also support Google Teachable Machine models.

Michael Nguyen 47 Dec 1, 2022
Flutter Music Player - A complete and open source music player designed in flutter.

Flutter Music Player A complete and open source music player designed in flutter. It is first complete music player designed in flutter. This app expl

Nabraj Khadka 3 Aug 20, 2022
Beautiful-Music-App-UI - Music App page UI Using Flutter

Beautiful Music App UI A Flutter App Music UI developed in Flutter Getting Start

Zain Basharat Ali 5 Jun 17, 2022
Flutter (web-only at this moment) plugin for recording audio (using the microphone).

Microphone Flutter (web-only at this moment) plugin for recording audio (using the microphone). Getting started To learn more about the plugin and get

null 28 Sep 26, 2022
A opensource, minimal and powerful audio player for android

A opensource, minimal and powerful audio player for android

Milad 7 Nov 2, 2022
Minimalistic local music player built with flutter for android.

Nano Music Player Simple local music player built with flutter. It uses the audioplayer plugin to play files, and path_provider to locate the external

Jan Hrastnik 34 Dec 17, 2022