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