play method

Future<void> play(
  1. Track track, {
  2. bool immediate = true,
  3. bool addToHistory = false,
})

Play a track immediately or add to queue

Implementation

Future<void> play(Track track, {bool immediate = true, bool addToHistory = false}) async {
  if (_sessionId == null) {
    throw Exception('No active session');
  }

  LavalinkLogger.info('Playing track: ${track.info.title}', tag: 'Player');

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

  if (immediate) {
    _currentTrack = track;
    _trackController.add(_currentTrack);
  }

  final update = PlayerUpdate(
    encodedTrack: track.encoded,
    position: 0,
  );

  await restClient.updatePlayer(_sessionId!, guildId, update);
  _isPlaying = true;
  _isPaused = false;
  _isStopped = false;
}