Skip to content

Commit

Permalink
Fix single repeat for real
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Aug 3, 2023
1 parent f5cc2a6 commit 465cbc2
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions lib/app/player/player_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ class PlayerModel extends SafeChangeNotifier {

_isCompletedSub = _player.stream.completed.listen((value) async {
if (value) {
if (repeatSingle == false) {
await playNext();
}
await playNext();
}
});

Expand All @@ -244,30 +242,26 @@ class PlayerModel extends SafeChangeNotifier {
}

Future<void> playNext() async {
if (nextAudio == null) return;
_setAudio(nextAudio);
_estimateNext();

if (!repeatSingle && nextAudio != null) {
_setAudio(nextAudio);
_estimateNext();
}
await play();
}

void _estimateNext() {
if (audio == null) return;

if (repeatSingle) {
nextAudio = audio;
} else {
if (queue.isNotEmpty == true && queue.contains(audio)) {
final currentIndex = queue.indexOf(audio!);
if (queue.isNotEmpty == true && queue.contains(audio)) {
final currentIndex = queue.indexOf(audio!);

if (shuffle && queue.length > 1) {
_randomNext();
if (shuffle && queue.length > 1) {
_randomNext();
} else {
if (currentIndex == queue.length - 1) {
nextAudio = queue.elementAt(0);
} else {
if (currentIndex == queue.length - 1) {
nextAudio = queue.elementAt(0);
} else {
nextAudio = queue.elementAt(queue.indexOf(audio!) + 1);
}
nextAudio = queue.elementAt(queue.indexOf(audio!) + 1);
}
}
}
Expand Down

0 comments on commit 465cbc2

Please sign in to comment.