🎨 Move _playYTDLStream function
This commit is contained in:
parent
737687e137
commit
08a8d0ff20
1 changed files with 47 additions and 39 deletions
|
@ -69,45 +69,6 @@ class Player {
|
||||||
client.on('voiceStateUpdate', (oldState, newState) => this._handleVoiceStateUpdate(oldState, newState))
|
client.on('voiceStateUpdate', (oldState, newState) => this._handleVoiceStateUpdate(oldState, newState))
|
||||||
}
|
}
|
||||||
|
|
||||||
_playYTDLStream (queue, updateFilter) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const currentStreamTime = updateFilter ? queue.voiceConnection.dispatcher.streamTime / 1000 : undefined
|
|
||||||
const encoderArgsFilters = []
|
|
||||||
Object.keys(queue.filters).forEach((filterName) => {
|
|
||||||
if (queue.filters[filterName]) {
|
|
||||||
encoderArgsFilters.push(filters[filterName])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
let encoderArgs
|
|
||||||
if (encoderArgsFilters.length < 1) {
|
|
||||||
encoderArgs = []
|
|
||||||
} else {
|
|
||||||
encoderArgs = ['-af', encoderArgsFilters.join(',')]
|
|
||||||
}
|
|
||||||
const newStream = ytdl(queue.playing.url, {
|
|
||||||
filter: 'audioonly',
|
|
||||||
opusEncoded: true,
|
|
||||||
encoderArgs,
|
|
||||||
seek: currentStreamTime
|
|
||||||
})
|
|
||||||
setTimeout(() => {
|
|
||||||
queue.voiceConnection.play(newStream, {
|
|
||||||
type: 'opus'
|
|
||||||
})
|
|
||||||
queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.volume / 200)
|
|
||||||
// When the track starts
|
|
||||||
queue.voiceConnection.dispatcher.on('start', () => {
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
// When the track ends
|
|
||||||
queue.voiceConnection.dispatcher.on('finish', () => {
|
|
||||||
// Play the next track
|
|
||||||
return this._playTrack(queue.guildID, false)
|
|
||||||
})
|
|
||||||
}, 1000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the filters for the guild
|
* Update the filters for the guild
|
||||||
* @param {Discord.Snowflake} guildID
|
* @param {Discord.Snowflake} guildID
|
||||||
|
@ -462,6 +423,53 @@ class Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play a stream in a channel
|
||||||
|
* @ignore
|
||||||
|
* @private
|
||||||
|
* @param {Queue} queue The queue to play
|
||||||
|
* @param {*} updateFilter Whether this method is called to update some ffmpeg filters
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
_playYTDLStream (queue, updateFilter) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const currentStreamTime = updateFilter ? queue.voiceConnection.dispatcher.streamTime / 1000 : undefined
|
||||||
|
const encoderArgsFilters = []
|
||||||
|
Object.keys(queue.filters).forEach((filterName) => {
|
||||||
|
if (queue.filters[filterName]) {
|
||||||
|
encoderArgsFilters.push(filters[filterName])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
let encoderArgs
|
||||||
|
if (encoderArgsFilters.length < 1) {
|
||||||
|
encoderArgs = []
|
||||||
|
} else {
|
||||||
|
encoderArgs = ['-af', encoderArgsFilters.join(',')]
|
||||||
|
}
|
||||||
|
const newStream = ytdl(queue.playing.url, {
|
||||||
|
filter: 'audioonly',
|
||||||
|
opusEncoded: true,
|
||||||
|
encoderArgs,
|
||||||
|
seek: currentStreamTime
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
queue.voiceConnection.play(newStream, {
|
||||||
|
type: 'opus'
|
||||||
|
})
|
||||||
|
queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.volume / 200)
|
||||||
|
// When the track starts
|
||||||
|
queue.voiceConnection.dispatcher.on('start', () => {
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
// When the track ends
|
||||||
|
queue.voiceConnection.dispatcher.on('finish', () => {
|
||||||
|
// Play the next track
|
||||||
|
return this._playTrack(queue.guildID, false)
|
||||||
|
})
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start playing a track in a guild
|
* Start playing a track in a guild
|
||||||
* @ignore
|
* @ignore
|
||||||
|
|
Loading…
Reference in a new issue