aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorMax Isom <[email protected]>2020-03-15 15:35:34 -0500
committerMax Isom <[email protected]>2020-03-15 15:35:34 -0500
commit3c169d113c21fc4f067400cf837b71abfc2f161d (patch)
treefce8d06cddac2f7660ec460f369f12510a5b8ba7 /src/services
parentbf0843dd1d8fbaa7c06cdc6110f45d46ca6b4052 (diff)
downloadmuse-3c169d113c21fc4f067400cf837b71abfc2f161d.tar.xz
muse-3c169d113c21fc4f067400cf837b71abfc2f161d.zip
Add forward seek
Diffstat (limited to 'src/services')
-rw-r--r--src/services/player.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/services/player.ts b/src/services/player.ts
index dfdf4b0..3ce68ae 100644
--- a/src/services/player.ts
+++ b/src/services/player.ts
@@ -21,6 +21,9 @@ export default class {
private voiceConnection: VoiceConnection | null = null;
private dispatcher: StreamDispatcher | null = null;
+ private lastStreamTime = 0;
+ private positionInSeconds = 0;
+
constructor(queue: Queue, cacheDir: string) {
this.queue = queue;
this.cacheDir = cacheDir;
@@ -52,6 +55,16 @@ export default class {
await this.waitForCache(currentSong.url);
this.attachListeners(this.voiceConnection.play(this.getCachedPath(currentSong.url), {seek: positionSeconds}));
+
+ this.positionInSeconds = positionSeconds;
+ }
+
+ async forwardSeek(positionSeconds: number): Promise<void> {
+ return this.seek(this.positionInSeconds + positionSeconds);
+ }
+
+ getPosition(): number {
+ return this.positionInSeconds;
}
async play(): Promise<void> {
@@ -224,6 +237,10 @@ export default class {
private attachListeners(stream: StreamDispatcher): void {
stream.on('speaking', async isSpeaking => {
+ // Update position
+ this.positionInSeconds += (stream.streamTime - this.lastStreamTime) / 1000;
+ this.lastStreamTime = stream.streamTime;
+
// Automatically advance queued song at end
if (!isSpeaking && this.status === STATUS.PLAYING) {
if (this.queue.get().length > 0) {