While working with just_audio, I need the progress of the audio and on the drag of the progress bar, I need to seek track to a particular position. I have referred to multiple answers but those were implemented with a third-party package.
So here is the implementation without any third-party package.
StreamBuilder<Duration?>(
stream: _audioPlayer.durationStream,
builder: (context, snapshot) {
final mediaDurationState = snapshot.data;
return StreamBuilder<Duration?>(
stream: _audioPlayer.positionStream,
builder: (context, snapshot) {
final mediaPositionState = snapshot.data;
return ProgressBar(
total: mediaDurationState ?? const Duration(),
progress: mediaPositionState ?? const Duration(),
barHeight: 2,
baseBarColor: Colors.black,
progressBarColor: Colors.white,
thumbColor: Colors.white,
timeLabelTextStyle: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: Colors.white),
timeLabelLocation: TimeLabelLocation.sides,
onSeek: (newPosition) {
_audioPlayer.seek(newPosition);
},
);
},
);
}
),