lavaplayer icon indicating copy to clipboard operation
lavaplayer copied to clipboard

Not Detecting the End of Tracks

Open confusedkernel opened this issue 2 years ago • 1 comments

As mentioned above, when the track finishes it doesn't automatically skip to the next track. After a bit of debugging, I found out that it doesn't seem like my current code fires the onTrackEnd event at all.

    public void nextTrack() {
        this.player.startTrack(queue.poll(), false);
        currentSong();
        System.out.println("skipped");
    }

    @Override
    public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) {
        System.out.println("does it work?");
        if (endReason.mayStartNext) {
            nextTrack();
            currentSong();
        }
    }

I've searched for any possible solution but so far none of the solutions worked for me, can someone help? My repository of the bot, the code is in MusicManager.

confusedkernel avatar Apr 07 '22 06:04 confusedkernel

You need to register your AudioEventAdapter with the player (called TrackScheduler in the example):

https://github.com/sedmelluq/lavaplayer/blob/707771af705b14ecc0c0ca4b5e5b6546e85f4b1c/demo-jda/src/main/java/com/sedmelluq/discord/lavaplayer/demo/jda/GuildMusicManager.java#L25-L26

Unless I missed something you're not doing that anywhere in your code. You just initialize your AudioEventAdapter, and that's it.

MCOfficer avatar Apr 07 '22 07:04 MCOfficer