Enhance audio player functionality by auto-playing on load and resetting position at end
This commit is contained in:
@@ -54,6 +54,7 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
||||
_duration = _audioPlayer.duration ?? Duration.zero;
|
||||
_isLoading = false;
|
||||
});
|
||||
_audioPlayer.play(); // Start playback automatically
|
||||
_audioPlayer.positionStream.listen((pos) {
|
||||
setState(() {
|
||||
_position = pos;
|
||||
@@ -76,6 +77,10 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
||||
_audioPlayer.pause();
|
||||
_iconController.reverse();
|
||||
} else {
|
||||
// If at end, seek to start
|
||||
if (_position >= _duration && _duration > Duration.zero) {
|
||||
_audioPlayer.seek(Duration.zero);
|
||||
}
|
||||
_audioPlayer.play();
|
||||
_iconController.forward();
|
||||
}
|
||||
@@ -83,16 +88,6 @@ class _AudioPlayerBarState extends State<AudioPlayerBar>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Sync icon animation with state
|
||||
if (_isPlaying &&
|
||||
_iconController.status != AnimationStatus.forward &&
|
||||
_iconController.value == 0.0) {
|
||||
_iconController.forward();
|
||||
} else if (!_isPlaying &&
|
||||
_iconController.status != AnimationStatus.reverse &&
|
||||
_iconController.value == 1.0) {
|
||||
_iconController.reverse();
|
||||
}
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
height: 48,
|
||||
|
||||
Reference in New Issue
Block a user