Skip to content

Commit

Permalink
audio player seek audio position by duration slider
Browse files Browse the repository at this point in the history
  • Loading branch information
nandodev-net committed Jun 18, 2022
1 parent 72539e8 commit 6f65364
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/views/audio_views/audio_player_fullscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
),
),
Slider(
activeColor: Colors.green,
activeColor: Color.fromARGB(255, 0, 255, 34),
value: watch(audioProvider)
.currentAudioPosition
?.inMilliseconds
Expand All @@ -179,7 +179,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
0.0,
onChanged: (value) {
setState(() {
// _currentSliderValue = value;
watch(audioProvider).seekAudio(Duration(milliseconds: value.toInt()));
});
//seekSound();
}),
Expand All @@ -192,7 +192,7 @@ class _PlayerScreenState extends State<PlayerScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
watch(audioProvider).playerAudioState,
_printDuration(parseDuration(watch(audioProvider).currentAudioPosition.toString())),
style:
TextStyle(color: Colors.black.withOpacity(0.5)),
),
Expand Down
4 changes: 4 additions & 0 deletions lib/views/audio_widgets/audio_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class AudioController extends ChangeNotifier {
exitAudio() {
audioPlayer.dispose();
}

seekAudio(Duration durationToSeek){
audioPlayer.seek(durationToSeek);
}
}

final audioProvider = ChangeNotifierProvider<AudioController>((ref) {
Expand Down

0 comments on commit 6f65364

Please sign in to comment.