Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #185 #187

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Lavalink4NET/Extensions/QueuedLavalinkPlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@

public static class QueuedLavalinkPlayerExtensions
{
/// <summary>
/// Adds a <see cref="TrackLoadResult"/> to the player's queue.<br/>
/// Returns the index of the track in the queue (or the last track added to the queue if <paramref name="loadResult"/> is a playlist)
/// </summary>
/// <param name="player">The player to enqueue the load result to.</param>
/// <param name="loadResult">The load result you want to enqueue.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The index of the track in the queue (or the last track added to the queue if <paramref name="loadResult"/> is a playlist)</returns>
/// <exception cref="InvalidOperationException">When the <paramref name="loadResult"/> contains no tracks.</exception>
public static async ValueTask<int> PlayAsync(this IQueuedLavalinkPlayer player, TrackLoadResult loadResult, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();

var queueOffset = default(int?);
int? queueOffset = default;

if (loadResult.Playlist is null)
{
// Single track
queueOffset ??= await player
queueOffset = await player
.PlayAsync(loadResult.Track!, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand All @@ -26,7 +35,7 @@ public static async ValueTask<int> PlayAsync(this IQueuedLavalinkPlayer player,
// Playlist
foreach (var track in loadResult.Tracks)
{
queueOffset ??= await player
queueOffset = await player
.PlayAsync(track, cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand Down
Loading