From 27e28ef41f6d6917f209b3e90acd1886f43d4024 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Sat, 4 Jul 2020 14:34:00 +0200 Subject: [PATCH] :zap: Improve stream time calculation --- src/Player.js | 10 +++++----- src/Queue.js | 5 +++++ src/Track.js | 5 ----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Player.js b/src/Player.js index db3743b..0aa0762 100644 --- a/src/Player.js +++ b/src/Player.js @@ -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) }) diff --git a/src/Queue.js b/src/Queue.js index 86a4f94..8f50d22 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -61,6 +61,11 @@ class Queue extends EventEmitter { * @type {Object} */ this.filters = {} + /** + * Additional stream time + * @type {Number} + */ + this.additionalStreamTime = 0 } get calculatedVolume () { diff --git a/src/Track.js b/src/Track.js index ce5e218..91cf172 100644 --- a/src/Track.js +++ b/src/Track.js @@ -56,11 +56,6 @@ class Track { * @type {Queue} */ this.queue = queue - - /** - * Stream time of the track (available on applying filters) - */ - this.streamTime = 0 } /**