Add optional streamOptions to playStream() functions (#663)

* Adding playStream options

Added optional volume and seek properties

* fixed code formatting

Edited my code styling to match with the rest of d.js

* Added Default Variable

* Added Documentation

Added documentation for the streamOptions parameter
Added a default value for seek in FFmpegConverterEngine
Removed redundantcy

* Fixed docs for voiceConnection

* Change _updateMember's notSame check from && to || (#665)

* Fixed git merge fail

* Built Docs. Again.........

* Hopefully finally fixed
This commit is contained in:
Perry Berman
2016-09-08 19:49:52 -07:00
committed by Schuyler Cebulskie
parent 4be7a1bfd1
commit f7a542f12b
7 changed files with 33 additions and 21 deletions

View File

@@ -203,6 +203,7 @@ class VoiceConnection extends EventEmitter {
/**
* Play the given file in the voice connection
* @param {string} file The path to the file
* @param {Object} [options] Optional streamOptions object. Currently accepts seek and volume properties.
* @returns {StreamDispatcher}
* @example
* // play files natively
@@ -212,36 +213,42 @@ class VoiceConnection extends EventEmitter {
* })
* .catch(console.log);
*/
playFile(file) {
return this.player.playFile(file);
playFile(file, { seek = 0, volume = 1 }) {
const options = { seek: seek, volume: volume };
return this.player.playFile(file, options);
}
/**
* Plays and converts an audio stream in the voice connection
* @param {ReadableStream} stream The audio stream to play
* @param {Object} [options] Optional streamOptions object. Currently accepts seek and volume properties.
* @returns {StreamDispatcher}
* @example
* // play streams using ytdl-core
* const ytdl = require('ytdl-core');
* const streamOptions = {seek: 0, volume: 1};
* voiceChannel.join()
* .then(connection => {
* const stream = ytdl('https://www.youtube.com/watch?v=XAWgeLF9EVQ', {filter : 'audioonly'});
* const dispatcher = connection.playStream(stream);
* const dispatcher = connection.playStream(stream, streamOptions);
* })
* .catch(console.log);
*/
playStream(stream) {
return this.player.playStream(stream);
playStream(stream, { seek = 0, volume = 1 }) {
const options = { seek: seek, volume: volume };
return this.player.playStream(stream, options);
}
/**
* Plays a stream of 16-bit signed stereo PCM at 48KHz.
* @param {ReadableStream} stream The audio stream to play.
* @param {Object} [options] Optional streamOptions object. Currently accepts seek and volume properties.
* @returns {StreamDispatcher}
*/
playConvertedStream(stream) {
playConvertedStream(stream, { seek = 0, volume = 1 }) {
const options = { seek: seek, volume: volume };
this._shutdown();
const dispatcher = this.player.playPCMStream(stream);
const dispatcher = this.player.playPCMStream(stream, options);
return dispatcher;
}