Sanskardham Gurukul
Sanskardham Gurukul

Reputation: 281

How to check Audio is finished or not in just audio library?

How to check audio is completed or not?

On finished change icon from pause to play.

Upvotes: 4

Views: 2522

Answers (3)

Việt Cao
Việt Cao

Reputation: 11

put it inside initState():

player.onPlayerComplete.listen((event) {
  print("Complete audio!");
  ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Complete audio!")));
  setState(() {

  });
});

Upvotes: 0

SULPHURIC ACID
SULPHURIC ACID

Reputation: 337

use audioplayers: https://pub.dev/packages/audioplayers

 player.onPlayerCompletion.listen((event) {
    onComplete();
    setState(() {
      position = duration;
    });
  });

Upvotes: 2

Netharu Methmitha
Netharu Methmitha

Reputation: 73

there is a way to listen to state changes you can use that

      audioPlayer.playerStateStream.listen((state) {
        if (state.processingState == ProcessingState.completed) {
          onComplete();
        }
      });

Upvotes: 7

Related Questions