audio_widget 1.0.0 copy "audio_widget: ^1.0.0" to clipboard
audio_widget: ^1.0.0 copied to clipboard

Play an audio on flutter can be as simple as display an image ! Just add a widget into the tree

audio_widget #

sample

(this widget does not display anything)

Play an audio on flutter can be as simple as display an image ! Just add a widget into the tree

Audio.assets(
  path: "assets/audios/country.mp3",
  play: true, //AudioWidget does not maintain the play state
  child: ...
)

⏯ Play / Pause #

Like usual Flutter widgets, just update the parameters of the Audio

//inside a stateful widget

bool _play = false;

@override
Widget build(BuildContext context) {
  return Audio.assets(
     path: "assets/audios/country.mp3",
     play: _play,
     child: RaisedButton(
       child: Text(
         _play ? "pause" : "play",
       ),
       onPressed: () {
         setState(() {
           _play = !_play;
         });
       },
     ),
  );
}

🛑 How to stop ? #

Just remove the Audio from the tree ! Or simply keep play: false

⏩ How to seek ? #

Just update the initialPosition of the Audio

//inside a stateful widget

Duration _seek;

@override
Widget build(BuildContext context) {
  return Audio.assets(
     path: "assets/audios/country.mp3",
     play: true,
     initialPosition: _seek,
     child: RaisedButton(
       child: Text("seek"),
       onPressed: () {
         setState(() {
           _seek = Duration(seconds: 30);
         });
       },
     ),
  );
}

🙉 Listeners #

Audio.assets(
  path: "assets/audios/country.mp3",
  play: _play,

  onReadyToPlay: (duration) {
     //onReadyToPlay
  },
  
  onPositionChanged: (current, duration) {
     //onReadyToPlay
  },

  child: ...
)

💽 Player #

By default, Audio uses Assets Audio Player to play its songs

You can change it just by create a new wrapper of AudioWidgetPlayer

class AudioWidgetMyPlayer extends AudioWidgetPlayer {
  final MyPlayer _player = MyPlayer();

  @override
  void play() => _player.play();

  @override
  void pause() => _player.pause();

  //etc.

and update the defaultAudioWidgetPlayer inside your main

void main() {
    defaultAudioWidgetPlayer = () => AudioWidgetMyPlayer();
    runApp(MyApp());
}
10
likes
30
pub points
0%
popularity

Publisher

unverified uploader

Play an audio on flutter can be as simple as display an image ! Just add a widget into the tree

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

assets_audio_player, flutter

More

Packages that depend on audio_widget