Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Dec 20, 2023
1 parent a01b4bd commit 9c1af6f
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lib/services/audio_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,12 @@ class MusifyAudioHandler extends BaseAudioHandler {
await super.onTaskRemoved();
}

bool get hasNext {
if (activePlaylist['list'].isEmpty) {
return audioPlayer.hasNext;
}
return id + 1 < activePlaylist['list'].length;
}
bool get hasNext => activePlaylist['list'].isEmpty
? audioPlayer.hasNext
: id + 1 < activePlaylist['list'].length;

bool get hasPrevious {
if (activePlaylist['list'].isEmpty) {
return audioPlayer.hasPrevious;
}
return id > 0;
}
bool get hasPrevious =>
activePlaylist['list'].isEmpty ? audioPlayer.hasPrevious : id > 0;

@override
Future<void> play() => audioPlayer.play();
Expand All @@ -225,20 +218,24 @@ class MusifyAudioHandler extends BaseAudioHandler {

@override
Future<void> skipToNext() async {
id = shuffleNotifier.value
? _generateRandomIndex(activePlaylist['list'].length)
: id + 1;
if (id + 1 < activePlaylist['list'].length) {
id = shuffleNotifier.value
? _generateRandomIndex(activePlaylist['list'].length)
: id + 1;

await playSong(activePlaylist['list'][id]);
await playSong(activePlaylist['list'][id]);
}
}

@override
Future<void> skipToPrevious() async {
id = shuffleNotifier.value
? _generateRandomIndex(activePlaylist['list'].length)
: id - 1;
if (id > 0) {
id = shuffleNotifier.value
? _generateRandomIndex(activePlaylist['list'].length)
: id - 1;

await playSong(activePlaylist['list'][id]);
await playSong(activePlaylist['list'][id]);
}
}

@override
Expand Down

0 comments on commit 9c1af6f

Please sign in to comment.