Discord.js: Node.js 10.9.0 - Dispatcher playFile Issue

Created on 2 Sep 2018  Â·  8Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
On the latest Node release 10.9.0, when using connection.playFile() the audio will be somewhat distorted, as though it's struggling to play the file. The main issue however is that the dispatcher will always end the playback before the sound has finished playing. On Windows, this early cut-off was observed to be ~1s. However, on Ubuntu 18.04, the audio instead cuts off just a second or two into playback, issuing a 'end' event to the dispatcher.

I'm not sure at exactly what version this issue started. I was on Node 10.x.0 and the dispatcher was working as normal, but the issue is certainly present on the latest Node 10.9.0 .

The file type (mp3/ogg) did not affect it, nor did the opus package used.

Include a reproducible code sample here, if possible:
The example dispatcher code provided in the documentation is enough to cause the issue.

Further details:

  • discord.js version: 11.4.2
  • Node.js version: 10.9.0
  • Operating system: Windows 10 1803/Ubuntu 18.04
  • Priority this issue should have – please be realistic and elaborate if possible: Probably high, it should be recommended to users that they do not install the latest Node.js version it seems.

  • [ ] I found this issue while running code on a __user account__
  • [ ] I have also tested the issue on latest master, commit hash:
low fixed on master voice bug

Most helpful comment

Okay. So it seems as if the latest master branch has resolved the issue. I believe you should still try to reproduce the issue on the current branch and the latest Node.js. If you have the same problem then maybe add a warning until the v12 is released.

Thanks a lot for your help, I hope this bug report is of some benefit and that the issue can be reproduced.

All 8 comments

Can you try using the master branch? Voice was basically rewritten in master and hopefully this fixes your issue. We have a few changes, e.g. playFile('song.mp3') is now just play('song.mp3') and stuff like member.voiceChannel is now member.voice.channel (you'll have to consult the docs)

@amishshah Can I use npm to pull the latest master branch, or do I git clone into node-modules? Sorry, I'm a little new to this.

Run npm i discordjs/discord.js, or yarn add discordjs/discord.js if you use yarn.

@kyranet thank you very much, I'll test this now and get back to you with results asap!

Okay. So it seems as if the latest master branch has resolved the issue. I believe you should still try to reproduce the issue on the current branch and the latest Node.js. If you have the same problem then maybe add a warning until the v12 is released.

Thanks a lot for your help, I hope this bug report is of some benefit and that the issue can be reproduced.

When the end event is emmited it should also give a reason can you try logging it
(
https://discord.js.org/#/docs/main/stable/class/StreamDispatcher?scrollTo=e-end
)

Ignore this, my bad.

@PLASMAchicken
I've updated to the latest Node.js 10.10 and reinstalled the latest stable npm version of Discord.js but now I can't play anything at all. Not sure if this is to do with the latest Node 10.10 but below is the code I used to originally test and produce the error in Node 10.9.0.

I have removed and reinstalled my node_modules after upgrading to Node 10.10 and downgrading to the latest stable version of discord.js (11.4.2) to make sure it's all fresh.

message.member.voiceChannel.join()
    .then(connection => { // Connection is an instance of VoiceConnection
        console.log("Joined voice channel!");
        message.reply('Waddup');
        let file = path.resolve("./sounds/brrp/bassdrop.mp3")
        console.log("File: " + file);

        const dispatcher = connection.playFile(path);

        let start = 0;
        let end = 0;

        dispatcher.on('start', () => {
            start = new Date();
            start = start.getTime();
            connection.player.streamingData.pausedTime = 0;
            dispatcher.setVolume(0.70);
            console.log("Playing");

        });

        dispatcher.on('debug', (info) => {
            console.log("Debug: " + info);
        });

        dispatcher.on('end', reason => {
            console.log("Finished");
            end = new Date();
            end = end.getTime();
            console.log("Playtime: " + (end - start) + "ms");
            console.log("End: " + reason);
        });
    });
"dependencies": {
    "bufferutil": "^4.0.0",
    "discord.js": "^11.4.2",
    "erlpack": "^0.1.2",
    "ffmpeg-binaries": "^4.0.0",
    "format-url": "^1.1.0",
    "jsonfile": "^4.0.0",
    "node-opus": "^0.3.0",
    "nodemon": "^1.18.3",
    "url-regex": "^4.1.1",
    "winston": "^3.0.0"
  }

Below is the console output from the code.

Joined voice channel!
File: D:\Documents\GitHub\Playground\Alexa\sounds\brrp\bassdrop.mp3
Playing
Finished
Playtime: 2ms
End: stream

As you can see, it joins but then does not play the audio file. No debug event info is printed. I'm really not sure what's happening here now. Node 10.10.0 works fine with the latest master branch of discord.js, once I change playFile to play and voiceChannel to voice.channel above to work with v12.

@PLASMAchicken

Alright so I've corrected the code and it's now reproducing the original error.

Test 1

The code from above is now playing a different file of length 1300ms.

However, the output is as follows:

Joined voice channel!
File: D:\Documents\GitHub\Playground\Alexa\sounds\dsl\Daniel Here you need some meat.mp3
Playing
Finished
Playtime: 727ms
End: stream

As you can see, the stream is only playing for 700ms, much shorter than the actual file.

The reason for ending is just stream ?

Test 2

A second test with file length 3030ms is streaming with a playtime of just 2587ms, which is accurate to when the file cuts off during playback.

Test 3

A third test with file length 14211ms is streamed for 13667ms.


It seems as though files are ending roughly 550ms before they should, regardless of length.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Brawaru picture Brawaru  Â·  3Comments

tom-barnes picture tom-barnes  Â·  3Comments

tiritto picture tiritto  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

Dmitry221060 picture Dmitry221060  Â·  3Comments