Maybe workable now
This commit is contained in:
parent
8a5083cc94
commit
1e6d95c609
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
listen := ":8080"
|
||||||
|
log.Println("Listening on", listen)
|
||||||
|
log.Fatal(http.ListenAndServe(listen, http.FileServer(http.Dir("."))))
|
||||||
|
}
|
|
@ -59,4 +59,8 @@ audio {
|
||||||
}
|
}
|
||||||
.fin {
|
.fin {
|
||||||
animation: pulse 1s infinite;
|
animation: pulse 1s infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
32
playlist.mjs
32
playlist.mjs
|
@ -39,8 +39,7 @@ class Playlist {
|
||||||
this.base = base
|
this.base = base
|
||||||
this.list = {}
|
this.list = {}
|
||||||
this.current = null
|
this.current = null
|
||||||
this.startedAt = 0
|
this.Stop()
|
||||||
this.pausedAt = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +77,7 @@ class Playlist {
|
||||||
if (!duration) {
|
if (!duration) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if (this.startedAt) {
|
if (this.Playing()) {
|
||||||
pos = ctx.currentTime - this.startedAt
|
pos = ctx.currentTime - this.startedAt
|
||||||
pos = Math.min(pos, duration)
|
pos = Math.min(pos, duration)
|
||||||
}
|
}
|
||||||
|
@ -96,7 +95,6 @@ class Playlist {
|
||||||
this.source.connect(ctx.destination)
|
this.source.connect(ctx.destination)
|
||||||
this.source.start(0, offset)
|
this.source.start(0, offset)
|
||||||
this.startedAt = ctx.currentTime - offset
|
this.startedAt = ctx.currentTime - offset
|
||||||
this.pausedAt = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pause() {
|
Pause() {
|
||||||
|
@ -111,11 +109,19 @@ class Playlist {
|
||||||
this.source.stop()
|
this.source.stop()
|
||||||
}
|
}
|
||||||
this.pausedAt = 0
|
this.pausedAt = 0
|
||||||
this.startedAt = 0
|
this.startedAt = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
Playing() {
|
||||||
|
if (this.startedAt > -1) {
|
||||||
|
let pos = ctx.currentTime - this.startedAt
|
||||||
|
return pos < this.Duration()
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayPause() {
|
PlayPause() {
|
||||||
if (this.startedAt) {
|
if (this.Playing()) {
|
||||||
this.Pause()
|
this.Pause()
|
||||||
} else {
|
} else {
|
||||||
this.Play()
|
this.Play()
|
||||||
|
@ -123,16 +129,16 @@ class Playlist {
|
||||||
}
|
}
|
||||||
|
|
||||||
Seek(pos) {
|
Seek(pos) {
|
||||||
if (this.startedAt) {
|
if (this.Playing()) {
|
||||||
this.play(pos)
|
this.Play(pos)
|
||||||
} else {
|
} else {
|
||||||
this.pausedAt = this.Duration() * pos
|
this.pausedAt = this.Duration() * pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentTime() {
|
CurrentTime() {
|
||||||
if (this.startedAt) {
|
if (this.Playing()) {
|
||||||
return ctx.currentTime - this.startedAt
|
return Math.min(ctx.currentTime - this.startedAt, this.Duration())
|
||||||
}
|
}
|
||||||
if (this.pausedAt) {
|
if (this.pausedAt) {
|
||||||
return this.pausedAt
|
return this.pausedAt
|
||||||
|
@ -319,8 +325,12 @@ function run() {
|
||||||
audio.addEventListener("ended", ended)
|
audio.addEventListener("ended", ended)
|
||||||
audio.addEventListener("volumechange", volumechange)
|
audio.addEventListener("volumechange", volumechange)
|
||||||
for (let li of document.querySelectorAll("#playlist li")) {
|
for (let li of document.querySelectorAll("#playlist li")) {
|
||||||
playlist.Add(li.textContent)
|
li.classList.add("loading")
|
||||||
li.addEventListener("click", loadTrack)
|
li.addEventListener("click", loadTrack)
|
||||||
|
playlist.Add(li.textContent)
|
||||||
|
.then(() => {
|
||||||
|
li.classList.remove("loading")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(() => timeupdate(), 250 * Millisecond)
|
setInterval(() => timeupdate(), 250 * Millisecond)
|
||||||
|
|
Loading…
Reference in New Issue