From ec9c9858f63b6a959b86419a2d1b974496275df6 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Mon, 18 Sep 2023 16:54:28 +0200 Subject: [PATCH 1/8] create and handle interval --- src/components/Player.vue | 105 +++++++++++--------------------------- 1 file changed, 29 insertions(+), 76 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index d5c8eff..01e1d44 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -1,26 +1,9 @@ @@ -105,7 +47,8 @@ export default { audio: {}, duration: 0, progress: 0, - interval: 0, + intervalProgress: 0, + intervalHistory: 0, preConvert: false, }; }, @@ -121,7 +64,6 @@ export default { play() { this.audio.play(); }, - pause() { if (!this.audio.paused) { this.audio.pause(); @@ -131,11 +73,17 @@ export default { this.duration = this.audio.duration; }, playing() { - window.clearInterval(this.interval); - this.interval = setInterval(() => { + window.clearInterval(this.intervalProgress); + window.clearInterval(this.intervalHistory); + + this.intervalProgress = setInterval(() => { this.progress = this.audio.currentTime; this.selectedTrack.percent = (100 / this.duration) * this.progress; }, 500); + + this.intervalHistory = setInterval(() => { + console.log(this.selectedTrack); + }, 10000); }, audioReset() { this.audio.pause(); @@ -238,7 +186,8 @@ export default { } }, reset() { - window.clearInterval(this.interval); + window.clearInterval(this.intervalProgress); + window.clearInterval(this.intervalHistory); if (!this.audio.paused) { this.audio.pause(); } @@ -409,17 +358,21 @@ export default { z-index: 1001; box-shadow: 0 0px 4px var(--shadow); } + #player .cover { width: 52px; margin-right: 4px; } + #playerBar { overflow: hidden; max-height: 52px; } -#playerBar > div { + +#playerBar>div { align-items: center; } + #playerControls button { display: flex; padding: 4px 12px; -- 2.45.2 From 8248073a4d45886767e67a3b0ed24e1e8c289fca Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Mon, 18 Sep 2023 17:41:42 +0200 Subject: [PATCH 2/8] prepare the intervals --- src/components/Player.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Player.vue b/src/components/Player.vue index 01e1d44..fbbbd8f 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -65,9 +65,12 @@ export default { this.audio.play(); }, pause() { - if (!this.audio.paused) { - this.audio.pause(); - } + this.audio.pause(); + + window.clearInterval(this.intervalProgress); + window.clearInterval(this.intervalHistory); + + this.progress = this.audio.currentTime; }, durationChanged() { this.duration = this.audio.duration; @@ -180,7 +183,7 @@ export default { return; } if (!this.audio.paused) { - this.audio.pause(); + this.pause(); } else if (this.audio.src != "") { this.audio.play(); } -- 2.45.2 From 239b538c4b418933403e3b1b3cf92ffeb92527f9 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Tue, 19 Sep 2023 01:56:09 +0200 Subject: [PATCH 3/8] added first functions --- public/config.json | 4 +- src/components/Player.vue | 47 +++++++++++--- src/components/dialogs/AlbumViewer.vue | 87 +++++++++++++------------- src/store/modules/user/actions.js | 17 +++++ 4 files changed, 100 insertions(+), 55 deletions(-) diff --git a/public/config.json b/public/config.json index a3b7d4a..f966bb7 100644 --- a/public/config.json +++ b/public/config.json @@ -1,5 +1,5 @@ { - "backend_de": "http://localhost:31204", - "backend_dev": "https://webplay.rocks", + "backend_dev": "http://localhost:31204", + "backend_de": "https://webplay.rocks", "backend": "https://webplay.rocks" } \ No newline at end of file diff --git a/src/components/Player.vue b/src/components/Player.vue index fbbbd8f..5053261 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -48,7 +48,7 @@ export default { duration: 0, progress: 0, intervalProgress: 0, - intervalHistory: 0, + intervalState: 0, preConvert: false, }; }, @@ -68,25 +68,27 @@ export default { this.audio.pause(); window.clearInterval(this.intervalProgress); - window.clearInterval(this.intervalHistory); + window.clearInterval(this.intervalState); - this.progress = this.audio.currentTime; + this.pushState(); }, durationChanged() { this.duration = this.audio.duration; }, playing() { window.clearInterval(this.intervalProgress); - window.clearInterval(this.intervalHistory); + window.clearInterval(this.intervalState); this.intervalProgress = setInterval(() => { this.progress = this.audio.currentTime; this.selectedTrack.percent = (100 / this.duration) * this.progress; }, 500); - this.intervalHistory = setInterval(() => { - console.log(this.selectedTrack); - }, 10000); + if (this.currentUser._id) { + this.intervalState = setInterval(() => { + this.pushState(); + }, 10000); + } }, audioReset() { this.audio.pause(); @@ -107,6 +109,14 @@ export default { this.audio.play(); } }, + skipToSecond(second) { + let was_paused = this.audio.paused; + this.audio.pause(); + this.audio.currentTime = second; + if (!was_paused) { + this.audio.play(); + } + }, playRadio(radio) { this.$store.commit("tracks/resetSelectedTrack"); this.audio.pause(); @@ -135,8 +145,12 @@ export default { this.pushHistoryItem(); - // Try to fix SAFARI - this.audio.play(); + if (this.selectedTrack.parent.progress) { + this.skipToSecond(this.selectedTrack.parent.progress.progress); + } else { + // Try to fix SAFARI + this.audio.play(); + } }, pushHistoryItem() { if (!this.currentUser._id) { @@ -190,7 +204,7 @@ export default { }, reset() { window.clearInterval(this.intervalProgress); - window.clearInterval(this.intervalHistory); + window.clearInterval(this.intervalState); if (!this.audio.paused) { this.audio.pause(); } @@ -251,6 +265,19 @@ export default { } this.$store.dispatch("user/savePlayerSettings"); }, + pushState() { + if (!this.currentUser._id) { + return; + } + this.progress = this.audio.currentTime; + let item = { + id: this.selectedTrack._id, + parentId: this.selectedTrack.parent._id, + type: "track", + progress: Math.round(this.progress) + } + this.$store.dispatch("user/saveProgress", item); + }, timeUpdate(event) { let percent = (event.target.currentTime / event.target.duration) * 100; if (percent > 10 && !this.preConvert) { diff --git a/src/components/dialogs/AlbumViewer.vue b/src/components/dialogs/AlbumViewer.vue index 487f0c7..0e84074 100644 --- a/src/components/dialogs/AlbumViewer.vue +++ b/src/components/dialogs/AlbumViewer.vue @@ -1,25 +1,12 @@