Reputation: 5917
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?
Upvotes: 1
Views: 1489
Reputation: 5917
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
.
Upvotes: 3