Closed tignear closed 3 years ago
This seems like a connection error with FFmpeg that could be solved by setting the reconnect
options when spawning FFmpeg. Could you try this and let me know if it still stops playback?
const { StreamType, createAudioResource } = require('@discordjs/voice');
const { FFmpeg } = require('prism-media');
const FFMPEG_OPUS_ARGUMENTS = [
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
];
const stream = new prism.FFmpeg({
args: ['-reconnect_streamed', '1', '-reconnect_at_eof', '1', '-reconnect_on_network_error', '1', '-reconnect_on_http_error', '1', '-reconnect_delay_max', '5', '-i', 'your url here', ...FFMPEG_OPUS_ARGUMENTS],
});
const resource = createAudioResource(stream, { inputType: StreamType.OggOpus });
It seems certain that it is a connection-related issue with FFmpeg. I did the following and it worked fine. Thank you!
I updated FFmpeg to v4.4. Because reconnect_on_network_error
and reconnect_on_http_error
is not supported before 4.4.
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.3.1
- prism-media: 1.2.9
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found
Encryption Libraries
- sodium: not found
- libsodium-wrappers: not found
- tweetnacl: 1.0.3
FFmpeg
- version: 4.4-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
reconnect_delay_max
was too short at 5 seconds, so it was extended to 30 seconds.
Added buffer to avoid Premature close.
Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
at OggDemuxer.onclose (internal/streams/end-of-stream.js:121:38)
at OggDemuxer.emit (events.js:327:22)
at emitCloseNT (internal/streams/destroy.js:87:10)
at processTicksAndRejections (internal/process/task_queues.js:79:21) {
code: 'ERR_STREAM_PREMATURE_CLOSE'
}
const { FFmpeg } = require('prism-media');
const { PassThrough } = require("stream");
const FFMPEG_OPUS_ARGUMENTS = [
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
];
const url = "https://www.dropbox.com/s/5f1l6seztxvq373/Cartoon%20-%20On%20_%20On%20%28feat.%20Daniel%20Levi%29%20_NCS%20Release_.mp3?dl=1";
const args = ['-reconnect', '1', '-reconnect_streamed', '1', '-reconnect_on_network_error', '1', '-reconnect_on_http_error', '4xx,5xx', '-reconnect_delay_max', '30', '-i', url, ...FFMPEG_OPUS_ARGUMENTS];
const stream = new FFmpeg({
args,
}).pipe(new PassThrough({
highWaterMark: 96000/8 * 30
}));
const resource = createAudioResource(stream, { inputType: StreamType.OggOpus });
Unfortunately, links from YouTube do not play :(
I've tried using prism-media. I even used the example from here word-for-word, and it didn't work.
When playing the audio from dropbox, the playback ends unexpectedly in the middle of the audio without throwing an error. However, when playing the downloaded audio file, it will play to the end without any issue.
ends unexpectedly
play to the end
Windows 10
Ubuntu 20.04(WSL2)
Relevant client options:
play to the end
ends unexpectedly