Flutter 使用flame/AudioPlayer时,如何停止AudioCache中的音频?
使用Flutter 使用flame/AudioPlayer时,如何停止AudioCache中的音频?,flutter,flame,Flutter,Flame,使用AudioCache播放本地资产时,它有一种播放方法: AudioCache audioPlayer = AudioCache(); await audioPlayer.play('alert_tone.mp3'); 但是没有停止的方法。如何停止它?所有启动音频的AudioCache方法都会返回所使用的AudioPlayer实例(可以是全新的或fixedPlayer的) 您可以使用该返回值来停止它: AudioCache cache = AudioCache(); AudioPlayer
AudioCache
播放本地资产时,它有一种播放方法:
AudioCache audioPlayer = AudioCache();
await audioPlayer.play('alert_tone.mp3');
但是没有停止的方法。如何停止它?所有启动音频的
AudioCache
方法都会返回所使用的AudioPlayer
实例(可以是全新的或fixedPlayer
的)
您可以使用该返回值来停止它:
AudioCache cache = AudioCache();
AudioPlayer player = await cache.play('alert_tone.mp3');
// ...
player.stop();
或使用音频播放器提供的任何其他控件