Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter flutter logo audio player

a flutter audio player plugin (objc/java) to play remote or local audio files.

flutter #1 audio player plugin
flutter #1 audio player plugin

features

  • [x] android & ios
  • [x] play (remote file)
  • [x] stop
  • [x] pause
  • [x] oncomplete
  • [x] onduration / oncurrentposition
  • [x] seek
  • [x] mute
flutter #1 audio player plugin

usage

example

to use this plugin :

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

audio player controls

future<void> play() async {
  await audioplayer.play(kurl);
  setstate(() => playerstate = playerstate.playing);
}

future<void> pause() async {
  await audioplayer.pause();
  setstate(() => playerstate = playerstate.paused);
}

future<void> stop() async {
  await audioplayer.stop();
  setstate(() {
    playerstate = playerstate.stopped;
    position = new duration();
  });
}

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

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>

download the full project for this post from the following button

this source is fully free for all time

download as zip


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top