diff --git a/lib/screens/now_playing_page.dart b/lib/screens/now_playing_page.dart index 6ed8d1d0..ecddb1e1 100644 --- a/lib/screens/now_playing_page.dart +++ b/lib/screens/now_playing_page.dart @@ -336,16 +336,24 @@ class NowPlayingPage extends StatelessWidget { ), Row( children: [ - IconButton( - icon: Icon( - FluentIcons.previous_24_filled, - color: audioHandler.hasPrevious - ? _primaryColor - : _secondaryColor, - ), - iconSize: screen * 0.115, - onPressed: () => audioHandler.skipToPrevious(), - splashColor: Colors.transparent, + ValueListenableBuilder( + valueListenable: repeatNotifier, + builder: (_, repeatMode, __) { + return IconButton( + icon: Icon( + FluentIcons.previous_24_filled, + color: audioHandler.hasPrevious + ? _primaryColor + : _secondaryColor, + ), + iconSize: screen * 0.115, + onPressed: () => + repeatNotifier.value == AudioServiceRepeatMode.one + ? audioHandler.playAgain() + : audioHandler.skipToPrevious(), + splashColor: Colors.transparent, + ); + }, ), const SizedBox(width: 10), StreamBuilder( @@ -373,7 +381,10 @@ class NowPlayingPage extends StatelessWidget { : _secondaryColor, ), iconSize: screen * 0.115, - onPressed: () => audioHandler.skipToNext(), + onPressed: () => + repeatNotifier.value == AudioServiceRepeatMode.one + ? audioHandler.playAgain() + : audioHandler.skipToNext(), splashColor: Colors.transparent, ); }, diff --git a/lib/services/audio_service.dart b/lib/services/audio_service.dart index dcdfb79e..3295a0d8 100644 --- a/lib/services/audio_service.dart +++ b/lib/services/audio_service.dart @@ -330,13 +330,7 @@ class MusifyAudioHandler extends BaseAudioHandler { @override Future skipToNext() async { - if (repeatNotifier.value == AudioServiceRepeatMode.one) { - // If repeat mode is set to repeat the current song, play the current song again - if (audioPlayer.playing && - audioPlayer.processingState != ProcessingState.buffering) { - await audioPlayer.seek(Duration.zero); - } - } else if (!hasNext && repeatNotifier.value == AudioServiceRepeatMode.all) { + if (!hasNext && repeatNotifier.value == AudioServiceRepeatMode.all) { // If repeat mode is set to repeat the playlist, start from the beginning await skipToSong(0); } else if (!hasNext && @@ -352,13 +346,7 @@ class MusifyAudioHandler extends BaseAudioHandler { @override Future skipToPrevious() async { - if (repeatNotifier.value == AudioServiceRepeatMode.one) { - // If repeat mode is set to repeat the current song, play the current song again - if (audioPlayer.playing) { - await audioPlayer.seek(Duration.zero); - } - } else if (!hasPrevious && - repeatNotifier.value == AudioServiceRepeatMode.all) { + if (!hasPrevious && repeatNotifier.value == AudioServiceRepeatMode.all) { // If repeat mode is set to repeat the playlist, start from the end await skipToSong(activePlaylist['list'].length - 1); } else if (hasPrevious) { @@ -367,6 +355,10 @@ class MusifyAudioHandler extends BaseAudioHandler { } } + Future playAgain() async { + await audioPlayer.seek(Duration.zero); + } + @override Future setShuffleMode(AudioServiceShuffleMode shuffleMode) async { final shuffleEnabled = shuffleMode != AudioServiceShuffleMode.none;