stop method

Future<void> stop({
  1. bool shouldClearQueue = false,
})

Stop playback completely (clears current track)

Implementation

Future<void> stop({bool shouldClearQueue = false}) async {
  if (_sessionId == null) return;

  LavalinkLogger.info('Stopping playback', tag: 'Player');

  // Use PlayerUpdate.stop() to ensure encodedTrack: null is sent
  final update = PlayerUpdate.stop();
  await restClient.updatePlayer(_sessionId!, guildId, update);

  if (_currentTrack != null) {
    _history.add(_currentTrack!);
    if (_history.length > 100) _history.removeAt(0);
  }

  _currentTrack = null;
  _isPlaying = false;
  _isPaused = false;
  _isStopped = true;
  _position = Duration.zero;
  _trackController.add(null);

  if (shouldClearQueue) {
    clearQueue();
  }
}