Skip to content

Commit

Permalink
fix: miscellaneous fixes connected to repeat function
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Dec 25, 2024
1 parent 7c70e41 commit d6d2200
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
33 changes: 22 additions & 11 deletions lib/screens/now_playing_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AudioServiceRepeatMode>(
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<PlaybackState>(
Expand Down Expand Up @@ -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,
);
},
Expand Down
20 changes: 6 additions & 14 deletions lib/services/audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,7 @@ class MusifyAudioHandler extends BaseAudioHandler {

@override
Future<void> 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 &&
Expand All @@ -352,13 +346,7 @@ class MusifyAudioHandler extends BaseAudioHandler {

@override
Future<void> 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) {
Expand All @@ -367,6 +355,10 @@ class MusifyAudioHandler extends BaseAudioHandler {
}
}

Future<void> playAgain() async {
await audioPlayer.seek(Duration.zero);
}

@override
Future<void> setShuffleMode(AudioServiceShuffleMode shuffleMode) async {
final shuffleEnabled = shuffleMode != AudioServiceShuffleMode.none;
Expand Down

0 comments on commit d6d2200

Please sign in to comment.