Discord.js: playFile() instantly end on osx

Created on 9 May 2018  路  19Comments  路  Source: discordjs/discord.js

Hello,

I'm working on a discord soundboard for my private server.

Considering this simplified example :

const Discord = require('discord.js');
const client = new Discord.Client();

client.login('xxxxxxxxxxxxxx'); // log the bot
client.channels.get('xxxxxxxxxxxxxxx').join() // join a voice channel
    .then(connection => {
        const dispatcher = connection.playFile('/path/to/my/file.mp3'); // play audio file

        // For debug purpose only :
        dispatcher.on('start', () => console.log('start'));
        dispatcher.on('end', () => console.log('end'));
    });

I started working on my mac (OSX 10.13.4) and when I use the playFile() function (or even the playArbitraryInput()) the bot instantly stop playing (as soon as 'start' is logged in console, 'end' is logged too). With no error.

So it's impossible to play any sound.
to be clearer, there is more informations :

  • I installed these 3 packages as explained in the readme.md :
$ yarn add discord.js
$ yarn add ffmpeg-binaries
$ yarn add node-opus

version of discord.js => v11.3.2
version of ffmpeg-binaries => v3.2.2-3
version of node-opus => v0.2.7

* I run my app as root (to be sure there is no access-right issue).

Then I tried to clone my project on my PC (Windows 10) and run it, and everything works !!!

So my question is : Why it doesn't run on my mac ?

medium voice bug

Most helpful comment

@hydrabolt I've switched to discord.[email protected] and now after reuploading the files it seems like its working, all my files are getting played on ec2.

All 19 comments

Same issue here. Except when using play() on v12.

Same issue for me.

I've had this issue in the past (albeit on earlier versions of discord.js) -- how long are the said audio clips you want to play?

If they're only a few seconds then I believe what fixed it for me back then was installing prism-media, also by hydrabolt. I actually don't remember the reason _why_ exactly prism-media fixed the problem, but it did for me, so it should be worth a try.

If they're longer audio files then I have no clue, but if you want to try the above.

Hello, thank you for the answer!

Files are not read regardless of the duration. I tested from few seconds to more than 2 minutes.
I tried your idea anyway, but that's does nothing more...

May be an odd question, but have you checked if the files are corrupted or something?

Can you open them with media players and the like?

Same error here. Files are not corrupted as they also work on a Windows clone of the project and are played correctly on iTunes. Also, when trying to install ffmpeg-binaries it throws the following error:

$ npm install ffmpeg-binaries
npm WARN deprecated [email protected]: 鈿狅笍  WARNING 鈿狅笍 tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar

> [email protected] install /Users/SrGMC/Documents/Developer/Discord/ScreamBot/node_modules/ffmpeg-binaries
> node install

Downloading
Extracting
Unhandled rejection Error: incorrect header check
    at Gunzip.zlibOnError (zlib.js:153:15)

Can you guys please try installing FFMPEG the usual way and not use ffmpeg-binaries?

It boggles my mind how it is "hard" to set a path for ffmpeg on windows, but I guess I understand thats why you want to use windows after all, to not deal with all of that.

But if you use macOS and/or Linux, please install it the normal way, make sure it's in your path and try again.

Done that using Homebrew (brew install ffmpeg) and downloading static builds (following this guide on StackExchange) with no luck. ffmpeg is installed in the usual path (/usr/local/bin/ffmpeg).

Also, trying to convert the audio file to opus and using playOpusStream() throws the following error: TypeError: this.stream.on is not a function

Running on macOS 10.13.4 with discord.[email protected], [email protected] and [email protected].

I do have a similar problem, though for me playFile() stops instantly on my ec2 Ubuntu Server though works on my Mac. Also the server is able to play some files though for others he stops instantly.

Hello @AlexanderProd,
Can you share an audio sample that works for you ?
I never found one that works for me...

I wish I could investigate.
To see if it's the same problem, and if it is, to find what the different could be, between files that work and files that don't.

@PaulSenon You can check out my repository, the following files in the audio folder are working on my ec2 server:

  • horns.mp3
  • audi.mp3
  • waiting.mp3 (uploaded a long track to see if the size is a problem, but isn't)

The other files are not working on my ec2, though all are working on my mac.
For more details I've opened up an own issue.

Can you guys try using the master version? It has a ton of voice fixes that might fix your problems.

@hydrabolt did the master version change something to connection.playFile and connection.playStream because I get an error saying they're not a function?

Yep, they're now merged into the play method, you should be able to pass the same parameters.

@hydrabolt I've switched to discord.[email protected] and now after reuploading the files it seems like its working, all my files are getting played on ec2.

Great news! 馃槂

Hi, a bit late sorry, but I finally tried your solutions.

The audio files of @AlexanderProd doesn't work for me.
Switching on discord.[email protected] doesn't fix anything.

I don't have time to test lot of thing yet, but I'll keep you in touch if I find something later...

@PaulSenon so just to make sure, you:

  • Are using master branch of discord.js
  • Have node-opus installed
  • Have ffmpeg installed and in your path

If you could also try converting a music file to an .ogg opus file (specify 48000Hz sampling rate, stereo audio, and opus codec) and then try playing it with this:

connection.play(fs.createReadStream('/path/to/file.ogg'), { type: 'ogg/opus', volume: false });

This bypasses FFmpeg and Opus so there's less chance of things being missing, might help in identifying the issue if it does/doesn't work.

Seems inactive for now, if you can reproduce this after the above suggestion please reopen!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Dmitry221060 picture Dmitry221060  路  3Comments

DatMayo picture DatMayo  路  3Comments

tom-barnes picture tom-barnes  路  3Comments

Blumlaut picture Blumlaut  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments