buildSlider method
Build the duration slider.
Implementation
Widget buildSlider() {
return MultiValueListenableBuilder(
valueListenables: [
_durationNotifier,
_positionNotifier,
_playerStateNotifier,
],
builder: (context, values, _) {
Duration duration = values.elementAt(0);
Duration position = values.elementAt(1);
PlayerState? playerState = values.elementAt(2);
double sliderValue = position.inMilliseconds.toDouble();
if (playerState == null ||
playerState.processingState == ProcessingState.completed) {
sliderValue = 0;
}
return Expanded(
child: Slider(
value: sliderValue,
max: (playerState == null ||
playerState.processingState == ProcessingState.completed)
? 1.0
: duration.inMilliseconds.toDouble(),
onChanged: (progress) {
if (playerState == null ||
playerState.processingState == ProcessingState.completed) {
sliderValue = progress.floor().toDouble();
_audioPlayer.seek(Duration(
milliseconds: sliderValue.toInt(),
));
} else {
sliderValue = progress.floor().toDouble();
_audioPlayer
.seek(Duration(milliseconds: sliderValue.toInt()));
}
}),
);
},
);
}