Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ <h6 class="now-playing-track-artist">{{ song.artists.join(", ") }}</h6>
</div>
<div class="now-playing-options">
<input type="hidden" :value="onRepeatChange">
<p>{{ state.completionStatus }}</p>
<button id="repeat" :class="{active: repeat === true}" @click="toggleRepeat()"><i class="material-icons">repeat</i></button>
<button id="loved" v-bind:class="{active: loved === true}" @click="toggleLoved"><i class="material-icons">favorite</i></button>
</div>
Expand Down
21 changes: 19 additions & 2 deletions scripts/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const state = new Vue({
ids: [],
src: "",
song: {},
elapsed: 0,
completion: 0,
instance: false,
tracker: false
Expand Down Expand Up @@ -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: {
Expand All @@ -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)
})

Expand All @@ -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)
})
Expand Down Expand Up @@ -126,7 +143,7 @@ const state = new Vue({
for(i in this.nowplaying.ids){
this.nowplaying.instance.pause(this.nowplaying.ids[i])
}
}
},
}
})

Expand Down