Skip to content

Commit

Permalink
feat: Implement auto-play feature
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Mar 11, 2024
1 parent ac0ef69 commit 8c52e59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Lavalink4NET/Players/Queued/IQueuedLavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface IQueuedLavalinkPlayer : ILavalinkPlayer

bool Shuffle { get; set; }

bool AutoPlay { get; set; }

ValueTask<int> PlayAsync(ITrackQueueItem queueItem, bool enqueue = true, TrackPlayProperties properties = default, CancellationToken cancellationToken = default);

ValueTask<int> PlayAsync(LavalinkTrack track, bool enqueue = true, TrackPlayProperties properties = default, CancellationToken cancellationToken = default);
Expand Down
5 changes: 4 additions & 1 deletion src/Lavalink4NET/Players/Queued/QueuedLavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public QueuedLavalinkPlayer(IPlayerProperties<QueuedLavalinkPlayer, QueuedLavali
_defaultTrackRepeatMode = options.DefaultTrackRepeatMode;
_clearHistoryOnStop = options.ClearHistoryOnStop;

AutoPlay = options.EnableAutoPlay;
RepeatMode = _defaultTrackRepeatMode;
}

Expand All @@ -56,6 +57,8 @@ public QueuedLavalinkPlayer(IPlayerProperties<QueuedLavalinkPlayer, QueuedLavali

public bool Shuffle { get; set; }

public bool AutoPlay { get; set; }

public async ValueTask<int> PlayAsync(ITrackQueueItem queueItem, bool enqueue = true, TrackPlayProperties properties = default, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -200,7 +203,7 @@ await base
.NotifyTrackEndedAsync(queueItem, endReason, cancellationToken)
.ConfigureAwait(false);

if (endReason.MayStartNext())
if (endReason.MayStartNext() && AutoPlay)
{
await PlayNextAsync(skipCount: 1, respectTrackRepeat: true, cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public record class QueuedLavalinkPlayerOptions : LavalinkPlayerOptions

public int? HistoryCapacity { get; init; } = 8;

public bool EnableAutoPlay { get; init; } = true;

public bool ClearQueueOnStop { get; init; } = true;

public bool ClearHistoryOnStop { get; init; } = false;
Expand Down

0 comments on commit 8c52e59

Please sign in to comment.