Flutter Just Audio播放事件 [英] Flutter Just Audio playbackEvent
问题描述
我在Flutter应用中使用了名为 Just Audio 的程序包.它提供了一个playBackEvent:playbackEvent.currentPosition,它显示了音频文件中已播放的时间位置.但是,我对Dart还是陌生的,并且不太了解如何为该事件订阅侦听器,以便我可以使用更改的值来做一些事情.
I am using a package called Just Audio in my Flutter app. It provides an playBackEvent: playbackEvent.currentPosition which shows the time position that has been played in the Audio file. However I'm a little new to Dart and don't really understand how to subscribe a listener to this event so that I can do something with the changing values.
我想做的是运行一个函数,该函数在值更改时设置状态,以便我可以显示进度并让用户知道他们当时在音频文件中的距离.
What I want to do is run a function which sets state when the value changes so I can show the progress and let the users know how far through the Audio file they are at that moment.
有人可以向我解释我该怎么做吗?
Can someone please explain to me how I should do this?
任何帮助将不胜感激.
推荐答案
完整的示例可用此处.
StreamBuilder<Duration>(
stream: _player.durationStream,
builder: (context, snapshot) {
final duration = snapshot.data ?? Duration.zero;
return StreamBuilder<Duration>(
stream: _player.getPositionStream(),
builder: (context, snapshot) {
var position = snapshot.data ?? Duration.zero;
if (position > duration) {
position = duration;
}
return SeekBar(
duration: duration,
position: position,
onChangeEnd: (newPosition) {
_player.seek(newPosition);
},
);
},
);
},
),
这篇关于Flutter Just Audio播放事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!