'When using flame/audioplayers, how to stop audios from AudioCache?

When using AudioCache to play local assets, it has a play method:

AudioCache audioPlayer = AudioCache();
await audioPlayer.play('alert_tone.mp3');

But there is no stop method. How can I stop it?



Solution 1:[1]

All AudioCache methods that start an audio return an instance of the AudioPlayer used (can be a brand new one or the fixedPlayer one).

You can use that return value to stop it:

AudioCache cache = AudioCache();
AudioPlayer player = await cache.play('alert_tone.mp3');

// ...

await player.stop();

Or to use any other controls provided by audioplayers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1