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

discontinued
outdatedDart 1 only

A flutter plugin to play audio files

AudioPlayer #

A Flutter audio plugin.

Features #

  • ✅ Android & iOS
    • ✅ play (remote file)
    • ✅ stop
    • ✅ pause
    • ✅ onComplete
    • ✅ onDuration / onCurrentPosition

screenshot

Usage #

Example

To use this plugin :

  • add the dependency to your pubspec.yaml file. This plugin is not yet published on pub.dartlang, so the dependency must be added with a local path.
  dependencies:
    flutter:
      sdk: flutter
    audioplayer:
  • instantiate a AudioPlayer instance
//...
AudioPlayer audioPlugin = new AudioPlayer();
//...

play, pause , stop #

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

Future stop() async {
  final result = await audioPlayer.stop();
  if (result == 1)
    setState(() {
    playerState = PlayerState.stopped;
    position = new Duration();
  });
}

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

The dart part of the plugin listen for platform calls :

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

audioPlayer.setPositionHandler((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 only #

  • ⚠️ this plugin is written in swift, so to use with in a Flutter/ObjC project, it seems to be needed 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.

128
likes
0
points
98
downloads

Publisher

verified publisherrxlabz.com

Weekly Downloads

A flutter plugin to play audio files

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on audioplayer