Skip to content

Commit

Permalink
fix: last track repeats
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Oct 15, 2023
1 parent 593bc2d commit ed6ca00
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/services/audio_player/mk_state_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class MkPlayerWithState extends Player {
if (!isCompleted) return;

_playerStateStream.add(AudioPlaybackState.completed);

if (loopMode == PlaylistMode.single) {
await super.open(_playlist!.medias[_playlist!.index], play: true);
} else {
Expand Down Expand Up @@ -166,10 +165,22 @@ class MkPlayerWithState extends Player {

final isLast = _playlist!.index == _playlist!.medias.length - 1;

if (loopMode == PlaylistMode.loop && isLast) {
playlist = _playlist!.copyWith(index: 0);
return super.open(_playlist!.medias[_playlist!.index], play: true);
} else if (!isLast) {
if (isLast) {
switch (loopMode) {
case PlaylistMode.loop:
playlist = _playlist!.copyWith(index: 0);
super.open(_playlist!.medias[_playlist!.index], play: true);
break;
case PlaylistMode.none:
// Fixes auto-repeating the last track
await super.stop();
await Future.delayed(const Duration(seconds: 2), () {
super.open(_playlist!.medias[_playlist!.index], play: false);
});
break;
default:
}
} else {
playlist = _playlist!.copyWith(index: _playlist!.index + 1);

return super.open(_playlist!.medias[_playlist!.index], play: true);
Expand Down

0 comments on commit ed6ca00

Please sign in to comment.