assets_audio_player
Play music/audio stored in assets files (simultaneously) directly from Flutter (android / ios / web).
You can also use play audio files from network using their url
? Import
Works with flutter: ">=1.12.13+hotfix.6 <2.0.0"
, be sure to upgrade your sdk
? Web support
And if you wan web support, enable web then add
You like the package ? buy me a kofi :)
Audio Source | Android | iOS | Web |
---|---|---|---|
Asset file (asset path) | ✅ | ✅ | ✅ |
Network file (url) | ✅ | ✅ | ✅ |
Local file (path) | ✅ | ✅ | ✅ |
Network LiveStream (url) | ✅ | ✅ | ✅ |
Commands | Android | iOS | Web |
---|---|---|---|
Play | ✅ | ✅ | ✅ |
Pause | ✅ | ✅ | ✅ |
Stop | ✅ | ✅ | ✅ |
Seek(position) | ✅ | ✅ | ✅ |
SeekBy(position) | ✅ | ✅ | ✅ |
Forward(speed) | ✅ | ✅ | ✅ |
Rewind(speed) | ✅ | ✅ | ✅ |
Next | ✅ | ✅ | ✅ |
Prev | ✅ | ✅ | ✅ |
Feature | Android | iOS | Web |
---|---|---|---|
Multiple players | ✅ | ✅ | ✅ |
Open Playlist | ✅ | ✅ | ✅ |
system notification | ✅ | ✅ | ? |
Respect System silent mode | ✅ | ✅ | ? |
Pause on phone call | ✅ | ✅ | ? |
Audio Widget | ✅ | ✅ | ✅ |
Properties | Android | iOS | Web |
---|---|---|---|
Loop | ✅ | ✅ | ✅ |
get/set Volume | ✅ | ✅ | ✅ |
get/set Play Speed | ✅ | ✅ | ✅ |
Listeners | Android | iOS | Web |
---|---|---|---|
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.
- Create an audio directory in your assets (not necessary named "audios")
- Declare it inside your pubspec.yaml
?️ Getting Started
You can also play network songs from url
And play songs from file
Notifications
on iOS, it will use MPNowPlayingInfoCenter
- Add metas inside your audio
- open with
showNotification: true
⛓ 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 !
Each player has an unique generated id
, you can retrieve or create them manually using
Playlist
Audio Widget
If you want a more flutter way to play audio, try the AudioWidget
!
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
⌛ Current song duration
⏳ Current position (in seconds)
or use a PlayerBuilder !
▶ IsPlaying
boolean observable representing the current mediaplayer playing state
or use a PlayerBuilder !
? 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
https://developer.android.com/reference/android/media/AudioManager.html?hl=fr#getRingerMode()
https://developer.apple.com/documentation/avfoundation/avaudiosessioncategorysoloambient
Listen the volume
or use a PlayerBuilder !
✋ Finished
Called when the current song has finished to play,
it gives the Playing audio that just finished
Called when the complete playlist has finished to play
? Looping
Network Policies (android/iOS)
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>