⚡ Improve stream time calculation
This commit is contained in:
parent
a0cdcbc461
commit
27e28ef41f
3 changed files with 10 additions and 10 deletions
|
@ -746,7 +746,7 @@ class Player {
|
||||||
const queue = this.queues.find((g) => g.guildID === guildID)
|
const queue = this.queues.find((g) => g.guildID === guildID)
|
||||||
if (!queue) return
|
if (!queue) return
|
||||||
// Stream time of the dispatcher
|
// Stream time of the dispatcher
|
||||||
const currentStreamTime = queue.voiceConnection.dispatcher.streamTime
|
const currentStreamTime = queue.calculatedStreamTime
|
||||||
// Total stream time
|
// Total stream time
|
||||||
const totalTime = queue.playing.durationMS
|
const totalTime = queue.playing.durationMS
|
||||||
// Stream progress
|
// Stream progress
|
||||||
|
@ -813,7 +813,7 @@ class Player {
|
||||||
filter: 'audioonly',
|
filter: 'audioonly',
|
||||||
opusEncoded: true,
|
opusEncoded: true,
|
||||||
encoderArgs,
|
encoderArgs,
|
||||||
seek: currentStreamTime
|
seek: currentStreamTime + queue.additionalStreamTime
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (queue.stream) queue.stream.destroy()
|
if (queue.stream) queue.stream.destroy()
|
||||||
|
@ -823,7 +823,7 @@ class Player {
|
||||||
bitrate: 'auto'
|
bitrate: 'auto'
|
||||||
})
|
})
|
||||||
if (currentStreamTime) {
|
if (currentStreamTime) {
|
||||||
queue.playing.streamTime += currentStreamTime
|
queue.additionalStreamTime += currentStreamTime
|
||||||
}
|
}
|
||||||
queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.calculatedVolume / 200)
|
queue.voiceConnection.dispatcher.setVolumeLogarithmic(queue.calculatedVolume / 200)
|
||||||
// When the track starts
|
// When the track starts
|
||||||
|
@ -832,8 +832,8 @@ class Player {
|
||||||
})
|
})
|
||||||
// When the track ends
|
// When the track ends
|
||||||
queue.voiceConnection.dispatcher.on('finish', () => {
|
queue.voiceConnection.dispatcher.on('finish', () => {
|
||||||
// reset streamTime
|
// Reset streamTime
|
||||||
if (queue.repeatMode) queue.playing.streamTime = 0
|
queue.additionalStreamTime = 0
|
||||||
// Play the next track
|
// Play the next track
|
||||||
return this._playTrack(queue.guildID, false)
|
return this._playTrack(queue.guildID, false)
|
||||||
})
|
})
|
||||||
|
|
|
@ -61,6 +61,11 @@ class Queue extends EventEmitter {
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
this.filters = {}
|
this.filters = {}
|
||||||
|
/**
|
||||||
|
* Additional stream time
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
this.additionalStreamTime = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
get calculatedVolume () {
|
get calculatedVolume () {
|
||||||
|
|
|
@ -56,11 +56,6 @@ class Track {
|
||||||
* @type {Queue}
|
* @type {Queue}
|
||||||
*/
|
*/
|
||||||
this.queue = queue
|
this.queue = queue
|
||||||
|
|
||||||
/**
|
|
||||||
* Stream time of the track (available on applying filters)
|
|
||||||
*/
|
|
||||||
this.streamTime = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue