A flutter plugin to play audio files


The audio really just as important as the unlocking part in any issues. Poor sound can ruin an otherwise spectacular production. Understanding the importance of audio is a crucial part of understanding what it really means. 

What better way to realize how much we rely on audio in our lives or at work? So, how do you play audio files? This is always a question for us. In this article, we would like to talk about the flutter plugin (ObjC/Java) to play remote or local audio files.


Some features of this audio plugin can show:

  • [x] Android & iOS
    • [x] play (remote file)
    • [x] stop
    • [x] pause
    • [x] onComplete
    • [x] onDuration / onCurrentPosition
    • [x] seek
    • [x] mute


To begin with simple example here:


To use this plugin :

      sdk: flutter

  • Instantiate an AudioPlayer instance
AudioPlayer audioPlugin = new AudioPlayer();

Player Controls

Future<void> play() async {
  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 listens 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) {
    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.


:warning: iOS App Transport Security

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



Written by James

A wallpapers apps made with flutter and API

An amazing Flutter audio recorder and player at one hand