diff --git a/index.html b/index.html
index 3074d34..28535bb 100644
--- a/index.html
+++ b/index.html
@@ -218,6 +218,7 @@
{{ song.artists.join(", ") }}
+
{{ state.completionStatus }}
diff --git a/scripts/state.js b/scripts/state.js
index 7062d45..6f5a7ac 100644
--- a/scripts/state.js
+++ b/scripts/state.js
@@ -20,6 +20,7 @@ const state = new Vue({
ids: [],
src: "",
song: {},
+ elapsed: 0,
completion: 0,
instance: false,
tracker: false
@@ -53,6 +54,20 @@ const state = new Vue({
})
return arr
+ },
+ completionStatus(){
+ let duration = Math.floor(this.nowplaying.elapsed)
+ let min = Math.floor(duration / 60)
+ let sec = Math.floor(duration % 60)
+ let completion = min.toString().padStart(2, "0") + ":" + sec.toString().padStart(2, "0")
+
+ duration = Math.floor(this.nowplaying.instance.duration())
+ min = Math.floor(duration / 60)
+ sec = Math.floor(duration % 60)
+ let length = min.toString().padStart(2, "0") + ":" + sec.toString().padStart(2, "0")
+
+ status = completion + "/" + length
+ return status
}
},
methods: {
@@ -70,8 +85,9 @@ const state = new Vue({
// When song starts playing
this.nowplaying.instance.on("play", () => {
this.nowplaying.tracker = setInterval(() => {
+ this.nowplaying.elapsed = this.nowplaying.instance.seek()
this.nowplaying.completion =
- this.nowplaying.instance.seek() * 1000 / (this.nowplaying.instance.duration() * 10)
+ this.nowplaying.instance.seek() * 100 / this.nowplaying.instance.duration()
}, 100)
})
@@ -84,6 +100,7 @@ const state = new Vue({
// When the song ends
this.nowplaying.instance.on("end", () => {
this.nowplaying.src = ""
+ this.nowplaying.elapsed = 0
this.nowplaying.completion = 0
clearInterval(this.nowplaying.tracker)
})
@@ -126,7 +143,7 @@ const state = new Vue({
for(i in this.nowplaying.ids){
this.nowplaying.instance.pause(this.nowplaying.ids[i])
}
- }
+ },
}
})