diff --git a/src/client/voice/VoiceConnection.js b/src/client/voice/VoiceConnection.js index 5dbd9c4e4..1cf80126d 100644 --- a/src/client/voice/VoiceConnection.js +++ b/src/client/voice/VoiceConnection.js @@ -4,6 +4,7 @@ const VoiceReceiver = require('./receiver/VoiceReceiver'); const Constants = require('../../util/Constants'); const AudioPlayer = require('./player/AudioPlayer'); const EventEmitter = require('events').EventEmitter; +const fs = require('fs'); /** * Represents a connection to a Voice Channel in Discord. @@ -41,7 +42,7 @@ class VoiceConnection extends EventEmitter { this.player.on('error', e => { this.emit('warn', e); - console.log('so yeah uh'+e); + console.log('so yeah uh' + e); this.player.cleanup(); }); @@ -92,6 +93,18 @@ class VoiceConnection extends EventEmitter { }); } + playFile(file) { + return this.playStream(fs.createReadStream(file)); + } + + playStream(stream) { + return this.player.playUnknownStream(stream); + } + + playConvertedStream(stream) { + return this.player.playPCMStream(stream); + } + } module.exports = VoiceConnection; diff --git a/src/client/voice/pcm/FfmpegConverterEngine.js b/src/client/voice/pcm/FfmpegConverterEngine.js index 2d54ac23e..0e3d8b1c4 100644 --- a/src/client/voice/pcm/FfmpegConverterEngine.js +++ b/src/client/voice/pcm/FfmpegConverterEngine.js @@ -1,6 +1,7 @@ const ConverterEngine = require('./ConverterEngine'); const ChildProcess = require('child_process'); const EventEmitter = require('events').EventEmitter; +require('longjohn'); class PCMConversionProcess extends EventEmitter { diff --git a/test/random.js b/test/random.js index b7ec51d11..2121c5775 100644 --- a/test/random.js +++ b/test/random.js @@ -161,7 +161,7 @@ let disp, con; client.on('message', msg => { if (msg.content.startsWith('/play')) { const chan = msg.content.split(' ').slice(1).join(' '); - con.player.playUnknownStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 }); + con.playStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 }); } if (msg.content.startsWith('/join')) { const chan = msg.content.split(' ').slice(1).join(' '); @@ -169,7 +169,7 @@ client.on('message', msg => { .then(conn => { con = conn; msg.reply('done'); - disp = conn.player.playUnknownStream(ytdl(song, {filter:'audioonly'}), { passes : 3 }); + disp = conn.playStream(ytdl(song, {filter:'audioonly'}), { passes : 3 }); conn.player.on('debug', console.log); conn.player.on('error', err => console.log(123, err)); })