Skip to content

Commit 0198936

Browse files
committed
feat: enhance skipToPrevious functionality (closes: #483)
1 parent f4c8a1b commit 0198936

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

lib/screens/now_playing_page.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,7 @@ class PlayerControlButtons extends StatelessWidget {
589589
color: audioHandler.hasPrevious ? primaryColor : secondaryColor,
590590
),
591591
iconSize: iconSize / 1.7,
592-
onPressed:
593-
() =>
594-
repeatNotifier.value == AudioServiceRepeatMode.one
595-
? audioHandler.playAgain()
596-
: audioHandler.skipToPrevious(),
592+
onPressed: () => audioHandler.skipToPrevious(),
597593
splashColor: Colors.transparent,
598594
);
599595
},

lib/services/audio_service.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,16 @@ class MusifyAudioHandler extends BaseAudioHandler {
937937
@override
938938
Future<void> skipToPrevious() async {
939939
try {
940+
// Get current playback position
941+
final currentPosition = audioPlayer.position;
942+
943+
// If the song has been playing for more than 3 seconds, restart it
944+
if (currentPosition.inSeconds > 3) {
945+
await audioPlayer.seek(Duration.zero);
946+
return;
947+
}
948+
949+
// Otherwise, go to previous song
940950
if (_currentQueueIndex > 0) {
941951
await _playFromQueue(_currentQueueIndex - 1);
942952
} else if (_historyList.isNotEmpty) {

0 commit comments

Comments
 (0)