audioplayers 0.5.1 copy "audioplayers: ^0.5.1" to clipboard
audioplayers: ^0.5.1 copied to clipboard

outdatedDart 1 only

A flutter plugin to play multiple audio files simultaneously

AudioPlayers #

This is a fork of rxlabz's audioplayer, with the difference that it supports playing multiple audios at the same time, and exposes volume controls.

It has the exact same API, but now you can create several new AudioPlayers, each will be handled individually.

Before you could only ever have one instance of the player, otherwise one would override the other.

Just import the fork, which is named audioplayers (mind the 's'), instead of the original:

  dependencies:
    ...
    audioplayers: ^0.5.1

Also, in 0.2.0, I've added the ability to disable logs with:

    AudioPlayer.logEnabled = false;

In 0.3.0, it supports iOS as well (thanks, @feroult)

In 0.4.0, volume control support was added (thanks, @pauldemarco)

In 0.4.1, a bug in iOS regard the seek functionality was fixed (thanks, @cosmok)

In 0.5.0, there was a huge change on Android code to improve performance (thanks, @the4thfloor)

In 0.5.1, there was a fix to work with Dart 2 (thanks, @efortuna)

Original Readme #

A Flutter audio plugin.

Features #

  • Android & iOS

    • ✅ play (remote and local file)
    • ✅ stop
    • ✅ pause
    • ✅ seek
    • ✅ onComplete
    • ✅ onDuration / onCurrentPosition
  • Supported formats

screenshot

Usage #

Example

To use this plugin :

  dependencies:
    flutter:
      sdk: flutter
    audioplayer:
  • instantiate an AudioPlayer instance
//...
AudioPlayer audioPlayer = new AudioPlayer();
//...

play, pause , stop, seek #

play() async {
  final result = await audioPlayer.play(kUrl);
  if (result == 1) setState(() => playerState = PlayerState.playing);
}

// add a isLocal parameter to play a local file
playLocal() async {
  final result = await audioPlayer.play(kUrl);
  if (result == 1) setState(() => playerState = PlayerState.playing);
}


pause() async {
  final result = await audioPlayer.pause();
  if (result == 1) setState(() => playerState = PlayerState.paused);
}

stop() async {
  final result = await audioPlayer.stop();
  if (result == 1) setState(() => playerState = PlayerState.stopped);
}

// seek 5 seconds from the beginning
audioPlayer.seek(5.0);

duration, position, complete, error (temporary api) #

The Dart part of the plugin listen for platform calls :

//...
audioPlayer.setDurationHandler((Duration d) => setState(() {
  duration = d;
}));

audioPlayer.setPositionHandler((Duration  p) => setState(() {
  position = p;
}));

audioPlayer.setCompletionHandler(() {
  onComplete();
  setState(() {
    position = duration;
  });
});

audioPlayer.setErrorHandler((msg) {
  print('audioPlayer error : $msg');
  setState(() {
    playerState = PlayerState.stopped;
    duration = new Duration(seconds: 0);
    position = new Duration(seconds: 0);
  });
});

iOS #

⚠️ Swift project #

  • this plugin is written in swift, so to use with in a Flutter/ObjC project, you need to convert the project to "Current swift syntax" ( Edit/Convert/current swift syntax)

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

Getting Started #

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

For help on editing plugin code, view the documentation.

3095
likes
0
pub points
100%
popularity

Publisher

verified publisherblue-fire.xyz

A flutter plugin to play multiple audio files simultaneously

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, uuid

More

Packages that depend on audioplayers