mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
make some stuffs
This commit is contained in:
@@ -93,16 +93,18 @@ class VoiceConnection extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
playFile(file) {
|
||||
return this.playStream(fs.createReadStream(file));
|
||||
playFile(file, options) {
|
||||
return this.playStream(fs.createReadStream(file), options);
|
||||
}
|
||||
|
||||
playStream(stream) {
|
||||
return this.player.playUnknownStream(stream);
|
||||
playStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
|
||||
const options = { seek, volume, passes };
|
||||
return this.player.playUnknownStream(stream, options);
|
||||
}
|
||||
|
||||
playConvertedStream(stream) {
|
||||
return this.player.playPCMStream(stream);
|
||||
playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
|
||||
const options = { seek, volume, passes };
|
||||
return this.player.playPCMStream(stream, options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,13 +38,15 @@ class StreamDispatcher extends EventEmitter {
|
||||
* aren't recommended, as it means you are using 5x more bandwidth. You _can_ edit this at runtime.
|
||||
* @type {number}
|
||||
*/
|
||||
this.passes = streamOptions.passes || 3;
|
||||
this.passes = streamOptions.passes || 1;
|
||||
|
||||
/**
|
||||
* Whether playing is paused
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.paused = false;
|
||||
|
||||
this.setVolume(streamOptions.volume || 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,15 +22,15 @@ class AudioPlayer extends EventEmitter {
|
||||
};
|
||||
}
|
||||
|
||||
playUnknownStream(stream) {
|
||||
playUnknownStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
|
||||
const options = { seek, volume, passes };
|
||||
stream.on('end', () => {
|
||||
|
||||
console.log(Date.now(), 'real input stream ended');
|
||||
console.log(Date.now(), 'real input stream ended');
|
||||
});
|
||||
stream.on('error', e => this.emit('error', e));
|
||||
const conversionProcess = this.audioToPCM.createConvertStream(0);
|
||||
const conversionProcess = this.audioToPCM.createConvertStream(options.seek);
|
||||
conversionProcess.setInput(stream);
|
||||
return this.playPCMStream(conversionProcess.process.stdout, conversionProcess);
|
||||
return this.playPCMStream(conversionProcess.process.stdout, conversionProcess, options);
|
||||
}
|
||||
|
||||
cleanup(checkStream, reason) {
|
||||
@@ -43,20 +43,18 @@ class AudioPlayer extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
playPCMStream(stream, converter) {
|
||||
playPCMStream(stream, converter, { seek = 0, volume = 1, passes = 1 } = {}) {
|
||||
const options = { seek, volume, passes };
|
||||
stream.on('end', () => {
|
||||
|
||||
console.log(Date.now(), 'pcm input stream ended');
|
||||
})
|
||||
console.log(Date.now(), 'pcm input stream ended');
|
||||
});
|
||||
this.cleanup(null, 'outstanding play stream');
|
||||
this.currentConverter = converter;
|
||||
if (this.currentDispatcher) {
|
||||
this.streamingData = this.currentDispatcher.streamingData;
|
||||
}
|
||||
stream.on('error', e => this.emit('error', e));
|
||||
const dispatcher = new StreamDispatcher(this, stream, this.streamingData, {
|
||||
volume: 1,
|
||||
});
|
||||
const dispatcher = new StreamDispatcher(this, stream, this.streamingData, options);
|
||||
dispatcher.on('error', e => this.emit('error', e));
|
||||
dispatcher.on('end', () => this.cleanup(dispatcher.stream, 'disp ended'));
|
||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||
|
||||
Reference in New Issue
Block a user