A Flutter audio plugin (Swift/Java) to play remote or local audio files on iOS / Android / MacOS / Web.

Online demo

[x] Android / iOS / MacOS / Web [x] play remote file [x] play local file ( not for the web) [x] stop [x] pause [x] onComplete [x] onDuration / onCurrentPosition [x] seek [x] mute



Example

To use this plugin :

Add the dependency to your pubspec.yaml file.

dependencies: flutter: sdk: flutter audioplayer: 0.8.1 audioplayer_web: 0.7.1

Instantiate an AudioPlayer instance

//... AudioPlayer audioPlugin = AudioPlayer(); //...

Player Controls #

audioPlayer.play(url); audioPlayer.pause(); audioPlayer.stop();

Status and current position #

The dart part of the plugin listen for platform calls :

//... _positionSubscription = audioPlayer.onAudioPositionChanged.listen( (p) => setState(() => position = p) ); _audioPlayerStateSubscription = audioPlayer.onPlayerStateChanged.listen((s) { if (s == AudioPlayerState.PLAYING) { setState(() => duration = audioPlayer.duration); } else if (s == AudioPlayerState.STOPPED) { onComplete(); setState(() { position = duration; }); } }, onError: (msg) { setState(() { playerState = PlayerState.stopped; duration = new Duration(seconds: 0); position = new Duration(seconds: 0); }); });

Do not forget to cancel all the subscriptions when the widget is disposed.

⚠️ iOS App Transport Security #

By default iOS forbids loading from non-https url. To cancel this restriction edit your .plist and add :

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

Background mode #

cf. enable background audio

Add this to entitlements files ( cf. DebugProfile.entitlements )

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

cf. Flutter MacOS security

If you get a MissingPluginException, try to flutter build apk on Android, or flutter build ios

Getting Started with Flutter #

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.