Yucked/Victoria

[ BUG ] Tracks sometimes get stuck at the end of playback.

AsakaJX opened this issue · 5 comments


Describe the bug/issue.

So, I just got sample for v6.0.1026 to work, my tracks is being played perfectly fine, but sometimes track just stop at the end and not dequeue itself. This happened in v5.2.8 aswell, this is the reason I updated version, because I thought it was fixed here, but it's not. I don't know what's wrong at all.

Stacktrace / Screenshots

I was able to use np command to check current timestamp of track and in v5.2.8 it just stopped like 1 - 5 seconds before track's end. I assume in v6.0.1026 it's the same (I couldn't receive exact position from that version, because player.Track.Position always returns 0 for some reason.

Screenshot from v5.2.8 attached.
image

My LavaLink application.json also from sample.

Yucked commented

How are you handling dequeue?

Sorry for late reply, I basically use your sample for version 5.2+ right now, only thing I changed is I'm using slash commands instead of prefix and I also removed auto-disconnect feauture.
So, this is function that's being called onTrackEnded:

private async Task OnTrackEnded(TrackEndedEventArgs args) {
    var player = args.Player;

    try {
        if (!player.Queue.TryDequeue(out var lavaTrack)) {
            await player.TextChannel.SendMessageAsync(embed: EB.Normal("Queue ended", "Add more tracks to the queue."));
            return;
        }

        if (lavaTrack is null) {
            await player.TextChannel.SendMessageAsync(embed: EB.Error("Couldn't play next track in queue (null)."));
            return;
        }

        await args.Player.PlayAsync(lavaTrack);
        await args.Player.TextChannel.SendMessageAsync(embed: EB.Normal($"{args.Reason.ToString()}: {args.Track.Title}", $"Currently playing: {lavaTrack.Title}"));
    } catch (Exception ex) {
        Console.WriteLine(ex);
    }
}

And this is function for play command:

[SlashCommand("music-play", "Add track to queue.", runMode: RunMode.Async)]
public async Task PlayAsync(
    [Summary("searchQuery", "search query")]
    string searchQuery,
    [Summary("type", "search type (temp)")]
    SearchType setType = SearchType.Direct
) {
    try {
        if (setType == SearchType.SoundCloud) {
            await RespondAsync(embed: EB.Error($"SoundCloud isn't working because dev is from Russia :)"));
            return;
        }

        if (string.IsNullOrWhiteSpace(searchQuery)) {
            await RespondAsync(embed: EB.Error($"Please check your spelling in search query."));
            return;
        }

        if (!_lavaNode.HasPlayer(Context.Guild)) {
            var voiceState = Context.User as IVoiceState;
            if (voiceState?.VoiceChannel == null) {
                await RespondAsync(embed: EB.Error($"You should be connected to voice channel."));
                return;
            }

            try {
                await _lavaNode.JoinAsync(voiceState.VoiceChannel, Context.Channel as ITextChannel);
                // await ReplyAsync(embed: EB.Success($"Joined {voiceState.VoiceChannel.Name}!"));
            } catch (Exception exception) {
                await ReplyAsync(embed: EB.Error($"{exception.Message}"));
            }
        }

        SearchType type = setType;

        var searchResponse = await _lavaNode.SearchAsync(type, searchQuery);
        if (searchResponse.Status is SearchStatus.LoadFailed or SearchStatus.NoMatches) {
            await RespondAsync(embed: EB.Error($"Couldn't find anything for `{searchQuery}`"));
            return;
        }

        var player = _lavaNode.GetPlayer(Context.Guild);
        if (!string.IsNullOrWhiteSpace(searchResponse.Playlist.Name)) {
            player.Queue.Enqueue(searchResponse.Tracks);
            await RespondAsync(embed: EB.Success($"Added {searchResponse.Tracks.Count} tracks to the queue."));
        } else {
            var track = searchResponse.Tracks.FirstOrDefault();
            player.Queue.Enqueue(track);

            await RespondAsync(embed: EB.Success($"**Added**: [{track?.Title}]({track?.Url}) by {track?.Author}\n**Duration**: {track?.Duration.ToString(@"hh\:mm\:ss")}"));
        }

        if (player.PlayerState is PlayerState.Playing or PlayerState.Paused) {
            return;
        }

        player.Queue.TryDequeue(out var lavaTrack);
        await player.PlayAsync(x => {
            x.Track = lavaTrack;
            x.ShouldPause = false;
        });
    } catch (Exception ex) {
        Log.NewLog(Logging.LogSeverity.Error, "Audio Module", ex.ToString());
    }
}

I have a bot that is more than one year old but i updated the Lavalink to the last version, and this started happening after some time, maybe it's a bug from Lavalink but I don't know for sure...

Yucked commented

If you update lavalink, the new way track handling is done is all via REST API which 5.x or 6.x don't support. Only 7.x has support for the new version of lavalink