onEnded method
Called when playback reaches the end of an item.
Implementation
Future<void> onEnded() async {
if (_loopMode == LoopModeMessage.one) {
await _seek(0, null);
_play();
} else {
final order = this.order;
final orderInv = getInv(order);
if (orderInv[_index!] + 1 < order.length) {
// move to next item
_index = order[orderInv[_index!] + 1];
await _currentAudioSourcePlayer!.load();
// Should always be true...
if (_playing) {
_play();
}
} else {
// reached end of playlist
if (_loopMode == LoopModeMessage.all) {
// Loop back to the beginning
if (order.length == 1) {
await _seek(0, null);
_play();
} else {
_index = order[0];
await _currentAudioSourcePlayer!.load();
// Should always be true...
if (_playing) {
_play();
}
}
} else {
transition(ProcessingStateMessage.completed);
}
}
}
}