audioplayer 0.8.1 copy "audioplayer: ^0.8.1" to clipboard
audioplayer: ^0.8.1 copied to clipboard

discontinued

A Flutter audio plugin (Swift/Java) to play remote or local audio files (ios, android, macos)

AudioPlayer #

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

Online demo

Features #

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

screenshot

Usage #

Example

To use this plugin :

  dependencies:
    flutter:
      sdk: flutter
    audioplayer: 0.8.1
    audioplayer_web: 0.7.1
copied to clipboard
  • Instantiate an AudioPlayer instance
//...
AudioPlayer audioPlugin = AudioPlayer();
//...
copied to clipboard

Player Controls #

audioPlayer.play(url);

audioPlayer.pause();

audioPlayer.stop();
copied to clipboard

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);
  });
});
copied to clipboard

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

iOS #

⚠️ 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>
copied to clipboard

Background mode #

cf. enable background audio

MacOS #

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

    <key>com.apple.security.network.client</key>
    <true/>
copied to clipboard

cf. Flutter MacOS security

Troubleshooting #

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

129
likes
25
points
103
downloads

Publisher

verified publisherrxlabz.com

Weekly Downloads

2024.09.29 - 2025.04.13

A Flutter audio plugin (Swift/Java) to play remote or local audio files (ios, android, macos)

Repository (GitHub)

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on audioplayer