use soundcloud
This commit is contained in:
parent
0bf75abd8e
commit
cfe6054bf6
2 changed files with 27 additions and 15 deletions
|
|
@ -3,10 +3,12 @@ import Layout from "../layouts/Layout.astro"
|
||||||
import "../styles/index.css"
|
import "../styles/index.css"
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout
|
||||||
<iframe
|
><iframe
|
||||||
id="music"
|
id="music"
|
||||||
src="https://www.youtube-nocookie.com/embed/0R6WIbx8ysE?enablejsapi=1"
|
width="100%"
|
||||||
|
height="300"
|
||||||
|
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/soundcloud%253Atracks%253A2196321083"
|
||||||
></iframe>
|
></iframe>
|
||||||
<button id="play">
|
<button id="play">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960">
|
||||||
|
|
@ -62,33 +64,38 @@ import "../styles/index.css"
|
||||||
const skip = document.querySelector("#skip")
|
const skip = document.querySelector("#skip")
|
||||||
const available = document.querySelector("#available") as HTMLDivElement
|
const available = document.querySelector("#available") as HTMLDivElement
|
||||||
|
|
||||||
var phase = 1
|
let phase = 1
|
||||||
var timer: ExtendableTimeout | null
|
let timer: ExtendableTimeout | null
|
||||||
|
|
||||||
const getTimeout = () => 2 ** phase * 1000
|
const getTimeout = () => 2 ** phase * 1000
|
||||||
|
|
||||||
const message = (command: String) =>
|
const message = (command: String, extra?: object) =>
|
||||||
(iframe as HTMLIFrameElement)?.contentWindow?.postMessage(
|
(iframe as HTMLIFrameElement)?.contentWindow?.postMessage(
|
||||||
JSON.stringify({
|
JSON.stringify({ method: command, ...extra }),
|
||||||
event: "command",
|
|
||||||
func: command,
|
|
||||||
}),
|
|
||||||
"*"
|
"*"
|
||||||
)
|
)
|
||||||
|
|
||||||
const playVideo = () => {
|
const playVideo = () => {
|
||||||
message("playVideo")
|
message("setVolume", { value: 30 })
|
||||||
|
message("play")
|
||||||
if (timer == null) {
|
if (timer == null) {
|
||||||
timer = new ExtendableTimeout(() => {
|
timer = new ExtendableTimeout(() => {
|
||||||
message("stopVideo")
|
message("seekTo", { value: 0 })
|
||||||
|
message("pause")
|
||||||
timer = null
|
timer = null
|
||||||
}, getTimeout())
|
}, getTimeout())
|
||||||
} else {
|
} else {
|
||||||
message("stopVideo")
|
message("seekTo", { value: 0 })
|
||||||
message("playVideo")
|
message("play")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iframe?.addEventListener("load", () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
message("play")
|
||||||
|
}, 300)
|
||||||
|
})
|
||||||
|
|
||||||
play?.addEventListener("click", playVideo)
|
play?.addEventListener("click", playVideo)
|
||||||
|
|
||||||
skip?.addEventListener("click", () => {
|
skip?.addEventListener("click", () => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
#music {
|
#music {
|
||||||
visibility: hidden;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
visibility: hidden;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#play {
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
#bar {
|
#bar {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue