Skip to content

Player Controls

MrCakeSlayer edited this page Sep 24, 2022 · 1 revision

Play track

To play a track, you first need to resolve one (for more details see "Resolving a track").

var myTrack = await myAudioService.GetTrackAsync("Hello World!", SearchMode.YouTube);
await myPlayer.PlayAsync(myTrack);
The QueuedLavalinkPlayer will enqueue the specified track when one is playing, you can change the behavior using the enqueue parameter.

Stop track

When a track is playing, it can be stopped using:

await myPlayer.StopAsync(disconnect: true);
The QueuedLavalinkPlayer will clear it's track queue when stopping.

Pause Track

This will pause the track. It can be resumed using myPlayer.ResumeAsync().

await myPlayer.PauseAsync();
This method throws an exception if the track is already paused. You can check with State != PlayerState.Paused.

Resume Track

This will resume the paused track.

await myPlayer.ResumeAsync();
This method throws an exception if the track is not paused. You can check with State == PlayerState.Paused.

Seeking

await myPlayer.SeekPositionAsync(TimeSpan.FromSeconds(12));

The above example will play the track at the 12th second.

Update Volume

await myPlayer.SetVolumeAsync(.2f);

The above example will set the player volume to 20%.

The player volume can be set from 0f (Muted / 0%) to 10f (1000%).

Disconnecting from the channel

Disconnecting from the voice channel, disconnects the player and leaves the voice channel.

await myPlayer.DisconnectAsync();

Connecting to a voice channel

await myPlayer.ConnectAsync(voiceChannelId, selfDeaf: false, selfMute: false);

Remarks on selfDeaf and selfMute:

When selfDeaf is true then the user will be self-deafened. This does not affect playing. When selfMute is false then the user will be self-muted. This will also mute the player.