Skip to content

Commit

Permalink
fix: Initially restore track information from initial player state
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Feb 6, 2024
1 parent 5e8430a commit c2b63c9
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/Lavalink4NET/Players/LavalinkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public LavalinkPlayer(IPlayerProperties<LavalinkPlayer, LavalinkPlayerOptions> p
State = PlayerState.Playing;
}

_nextTrack = CurrentTrack is not null
? new TrackQueueItem(new TrackReference(CurrentTrack))
_currentItem = _nextTrack = properties.InitialState.CurrentTrack is not null
? new TrackQueueItem(new TrackReference(RestoreTrack(properties.InitialState.CurrentTrack)))
: null;

Refresh(properties.InitialState);
Expand Down Expand Up @@ -424,23 +424,6 @@ private async ValueTask PerformUpdateAsync(PlayerUpdateProperties properties, Ca

private void Refresh(PlayerInformationModel model)
{
static LavalinkTrack RestoreTrack(TrackModel track) => new()
{
Author = track.Information.Author,
Identifier = track.Information.Identifier,
Title = track.Information.Title,
Duration = track.Information.Duration,
IsLiveStream = track.Information.IsLiveStream,
IsSeekable = track.Information.IsSeekable,
Uri = track.Information.Uri,
SourceName = track.Information.SourceName,
StartPosition = track.Information.Position,
ArtworkUri = track.Information.ArtworkUri,
Isrc = track.Information.Isrc,
TrackData = track.Data,
AdditionalInformation = track.AdditionalInformation,
};

ArgumentNullException.ThrowIfNull(model);
Debug.Assert(model.GuildId == GuildId);

Expand Down Expand Up @@ -668,6 +651,23 @@ private ValueTask UpdateVoiceCredentialsAsync(CancellationToken cancellationToke

return new TrackQueueItem(new TrackReference(track));
}
private static LavalinkTrack RestoreTrack(TrackModel track) => new()
{
Author = track.Information.Author,
Identifier = track.Information.Identifier,
Title = track.Information.Title,
Duration = track.Information.Duration,
IsLiveStream = track.Information.IsLiveStream,
IsSeekable = track.Information.IsSeekable,
Uri = track.Information.Uri,
SourceName = track.Information.SourceName,
StartPosition = track.Information.Position,
ArtworkUri = track.Information.ArtworkUri,
Isrc = track.Information.Isrc,
TrackData = track.Data,
AdditionalInformation = track.AdditionalInformation,
};

}

internal static partial class Logging
Expand Down

0 comments on commit c2b63c9

Please sign in to comment.