mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Add method to play back the output from an arbitrary ffmpeg cmd
This commit is contained in:
@@ -107,4 +107,37 @@ export default class AudioEncoder {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
encodeArbitraryFFmpeg(ffmpegOptions) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
// add options discord.js needs
|
||||
var options = ffmpegOptions.concat([
|
||||
'-loglevel', '0',
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-ac', 2,
|
||||
'pipe:1'
|
||||
]);
|
||||
var enc = cpoc.spawn(self.getCommand(), options, { stdio: ['pipe', 'pipe', 'ignore'] });
|
||||
|
||||
enc.stdout.once("readable", function () {
|
||||
resolve({
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
channels : 2
|
||||
});
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function () {
|
||||
console.log("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function () {
|
||||
console.log("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,6 +253,33 @@ export default class VoiceConnection extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
playArbitraryFFmpeg(ffmpegOptions, callback = function (err, str) { }) {
|
||||
var self = this;
|
||||
self.stopPlaying();
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
this.encoder
|
||||
.encodeArbitraryFFmpeg(ffmpegOptions)
|
||||
.catch(error)
|
||||
.then(data => {
|
||||
self.streamProc = data.proc;
|
||||
self.instream = data.instream;
|
||||
var intent = self.playStream(data.stream);
|
||||
resolve(intent);
|
||||
callback(null, intent);
|
||||
|
||||
});
|
||||
function error(e = true) {
|
||||
reject(e);
|
||||
callback(e);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
init() {
|
||||
var self = this;
|
||||
console.log("\n\nendpoint:", this.endpoint, "\n\n");
|
||||
|
||||
Reference in New Issue
Block a user