【发布时间】:2019-12-07 20:33:33
【问题描述】:
使用AudioCache播放本地资源时,有一个播放方法:
AudioCache audioPlayer = AudioCache();
await audioPlayer.play('alert_tone.mp3');
但是没有停止方法。我怎样才能阻止它?
【问题讨论】:
使用AudioCache播放本地资源时,有一个播放方法:
AudioCache audioPlayer = AudioCache();
await audioPlayer.play('alert_tone.mp3');
但是没有停止方法。我怎样才能阻止它?
【问题讨论】:
所有启动音频的AudioCache 方法都返回一个使用的AudioPlayer 的实例(可以是全新的一个或fixedPlayer 一个)。
您可以使用该返回值来停止它:
AudioCache cache = AudioCache();
AudioPlayer player = await cache.play('alert_tone.mp3');
// ...
await player.stop();
或者使用audioplayers提供的任何其他控件。
【讨论】:
await 停止:await player.stop();。