Improve stream time calculation

This commit is contained in:
Androz2091 2020-07-04 14:34:00 +02:00
parent a0cdcbc461
commit 27e28ef41f
3 changed files with 10 additions and 10 deletions

View file

@ -746,7 +746,7 @@ class Player {
const queue = this.queues.find((g) => g.guildID === guildID)
if (!queue) return
// Stream time of the dispatcher
const currentStreamTime = queue.voiceConnection.dispatcher.streamTime
const currentStreamTime = queue.calculatedStreamTime
// Total stream time
const totalTime = queue.playing.durationMS
// Stream progress
@ -813,7 +813,7 @@ class Player {
filter: 'audioonly',
opusEncoded: true,
encoderArgs,
seek: currentStreamTime
seek: currentStreamTime + queue.additionalStreamTime
})
setTimeout(() => {
if (queue.stream) queue.stream.destroy()
@ -823,7 +823,7 @@ class Player {
bitrate: 'auto'
})
if (currentStreamTime) {
queue.playing.streamTime += currentStreamTime
queue.additionalStreamTime += currentStreamTime
}
queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.calculatedVolume / 200)
// When the track starts
@ -832,8 +832,8 @@ class Player {
})
// When the track ends
queue.voiceConnection.dispatcher.on('finish', () => {
// reset streamTime
if (queue.repeatMode) queue.playing.streamTime = 0
// Reset streamTime
queue.additionalStreamTime = 0
// Play the next track
return this._playTrack(queue.guildID, false)
})

View file

@ -61,6 +61,11 @@ class Queue extends EventEmitter {
* @type {Object}
*/
this.filters = {}
/**
* Additional stream time
* @type {Number}
*/
this.additionalStreamTime = 0
}
get calculatedVolume () {

View file

@ -56,11 +56,6 @@ class Track {
* @type {Queue}
*/
this.queue = queue
/**
* Stream time of the track (available on applying filters)
*/
this.streamTime = 0
}
/**