ytdl-core and play-dl interruption problem

63 views Asked by At

The audio will suddenly pause when I'm halfway through playing, and it will show AudioPlayerError: aborted I have seen bug issues here(GitHub) , but no one has come up with a solution until 2024

use ytdl

const stream = ytdl(this.queue[guildID][0].url)

use play-dl

const play_stream = await play.stream(this.queue[guildID][0].url, {
      discordPlayerCompatibility: true,
})

Both of these things will work when I use

const resource = createAudioResource(play_stream.stream, {
             inputType: StreamType.WebmOpus
         });

Suddenly paused playback on the way but if i try

const outputStream = fs.createWriteStream('audio.mp3');
         play_stream.stream.pipe(outputStream);
         outputStream.on('finish', () => {
             console.log('The audio data has been successfully saved to the file.');
         });

The download will be completed quickly, which shows that it is a cache problem.

1

There are 1 answers

2
noobis004 On

this looks weird to me

discordPlayerCompatibility: true,

discordPlayerCompatibility is only if you use discord-player (which is it's own library) which is not needed if you use discord.js/voice

i use this instead and it should work

const play_stream = await play.stream(this.queue[guildID][0].url);
let resource = createAudioResource(play_stream.stream, {
    inputType: stream.type,
});

this might also be a problem with your audioplayer if so setting the noSubscriberBehaviour to play (this may help)

 const audioplayer = createAudioPlayer({
                    behaviors: {
                        noSubscriber: NoSubscriberBehavior.play,
                    }
                })

(you will need to change it to work with your code)