Audio Resources immediately goes from "playing" to "idle" despite having NoSubscriberBehavior.Play

Core Dependencies
- @discordjs/voice: [VI]{{inject}}[/VI]
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: 0.0.8

Encryption Libraries
- sodium-native: 4.1.1
- sodium: 3.0.2
- libsodium-wrappers: 0.7.13
- tweetnacl: 1.0.3

FFmpeg
- version: 4.4.1-static https://johnvansickle.com/ffmpeg/
- libopus: yes
Core Dependencies
- @discordjs/voice: [VI]{{inject}}[/VI]
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: 0.0.8

Encryption Libraries
- sodium-native: 4.1.1
- sodium: 3.0.2
- libsodium-wrappers: 0.7.13
- tweetnacl: 1.0.3

FFmpeg
- version: 4.4.1-static https://johnvansickle.com/ffmpeg/
- libopus: yes
It doesn't do this locally and only does it on my hosted server.
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});
debug: state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
debug: state change:
from {"status":"playing","missedFrames":0,"playbackDuration":120,"resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}
debug: state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
debug: state change:
from {"status":"playing","missedFrames":0,"playbackDuration":120,"resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}
4 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Jhawsh
JhawshOP8mo ago
const { createAudioResource, createAudioPlayer, StreamType, NoSubscriberBehavior } = require('@discordjs/voice');

const resource = createAudioResource('https://mp3stream.co', {
inputType: StreamType.Opus,
});

const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});

player.on('error', error => {
console.error('Error:', error.message);
});

player.on('debug', error => {
console.error('Debug:', error);
});


resource.playStream.on('error', error => {
console.error('Error:', error.message);
});

player.play(resource);

module.exports = {player, resource};
const { createAudioResource, createAudioPlayer, StreamType, NoSubscriberBehavior } = require('@discordjs/voice');

const resource = createAudioResource('https://mp3stream.co', {
inputType: StreamType.Opus,
});

const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});

player.on('error', error => {
console.error('Error:', error.message);
});

player.on('debug', error => {
console.error('Debug:', error);
});


resource.playStream.on('error', error => {
console.error('Error:', error.message);
});

player.play(resource);

module.exports = {player, resource};
duck
duck8mo ago
are you absolutely sure that that's a valid url for an audio stream? the Opus stream type is for opus streams (in object mode) if you were looking to play an ogg file, you'd want OggOpus but are you sure that a website named mp3stream would provide something other than mp3?
Jhawsh
JhawshOP8mo ago
I just removed url, but I am 100% sure the stream works, (I've tried with OggOpus and the ogg streaming link). The implementation actually works fine locally (and on a different hosted server), but for some reason on my new host doesn't work. My only thoughts is it could be something to do with the firewall, but I am not seeing anything suggesting that in the debug/errors
const { createAudioResource, createAudioPlayer, StreamType, NoSubscriberBehavior } = require('@discordjs/voice');

const resource = createAudioResource('http://radio.truckers.fm/radio-ogg', {
inputType: StreamType.OggOpus,
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});

player.on('error', error => {
console.error('Error:', error.message);
});

resource.playStream.on('error', error => {
console.error('Error:', error.message);
});

player.play(resource);

module.exports = {player, resource};
const { createAudioResource, createAudioPlayer, StreamType, NoSubscriberBehavior } = require('@discordjs/voice');

const resource = createAudioResource('http://radio.truckers.fm/radio-ogg', {
inputType: StreamType.OggOpus,
});
const player = createAudioPlayer({
behaviors: {
noSubscriber: NoSubscriberBehavior.Play,
maxMissedFrames: Math.round(5000 / 20),
},
});

player.on('error', error => {
console.error('Error:', error.message);
});

resource.playStream.on('error', error => {
console.error('Error:', error.message);
});

player.play(resource);

module.exports = {player, resource};
Here is the exact code which runs locally fine, but on a hosted server does not play anything. The voice channel joining code is here (it does join the channel fine)
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
});

connection.subscribe(player.player);

connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
// Seems to be reconnecting to a new channel - ignore disconnect
} catch (error) {
// Seems to be a real disconnect which SHOULDN'T be recovered from
connection.destroy();
}
});
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guildId,
adapterCreator: interaction.guild.voiceAdapterCreator
});

connection.subscribe(player.player);

connection.on(VoiceConnectionStatus.Disconnected, async (oldState, newState) => {
try {
await Promise.race([
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
entersState(connection, VoiceConnectionStatus.Connecting, 5_000),
]);
// Seems to be reconnecting to a new channel - ignore disconnect
} catch (error) {
// Seems to be a real disconnect which SHOULDN'T be recovered from
connection.destroy();
}
});
I've disabled the firewall on the server to rule that out. I am able to use ffmpeg -i http://radio.truckers.fm/radio-ogg -c copy test.ogg to output the stream to an ogg file. Its also accesible via ssh by just typing 'ffmpeg'. Unless it needs to be put anywhere special for discordjs to pick it up For future reference whoever may come across this, I was having issue with the implementation of
createAudioResource('http://radio.truckers.fm/radio-ogg', {
inputType: StreamType.OggOpus,
});
createAudioResource('http://radio.truckers.fm/radio-ogg', {
inputType: StreamType.OggOpus,
});
and ended up subsituting it for
const stream = got.stream("http://radio.truckers.fm/radio-ogg");
let resource = createAudioResource(stream);
const stream = got.stream("http://radio.truckers.fm/radio-ogg");
let resource = createAudioResource(stream);
Both impl worked locally but something in the server environment must of been having issues.
Want results from more Discord servers?
Add your server