try using soundcloud button

This commit is contained in:
Henry Hiles 2026-01-02 17:32:39 -05:00
commit ae614b92bb
No known key found for this signature in database
3 changed files with 58 additions and 36 deletions

View file

@ -3,21 +3,22 @@ import Layout from "../layouts/Layout.astro"
import "../styles/index.css"
---
<Layout
><iframe
id="music"
width="100%"
height="300"
allow="encrypted-media *;"
<Layout>
<div id="play">
<iframe
title="SoundCloud Play Button"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/soundcloud%253Atracks%253A2196321083"
></iframe>
<button id="play">
<span class="fake-button">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960">
<path
d="M320-273v-414q0-17 12-28.5t28-11.5q5 0 10.5 1.5T381-721l326 207q9 6 13.5 15t4.5 19q0 10-4.5 19T707-446L381-239q-5 3-10.5 4.5T360-233q-16 0-28-11.5T320-273Z"
></path>
</svg>
</button>
</span>
</div>
<section id="bar">
<div id="bars">
<div></div><div></div><div></div>
@ -60,23 +61,23 @@ import "../styles/index.css"
}
}
const iframe = document.querySelector("#music")
const play = document.querySelector("#play")
const iframe = document.querySelector("iframe")
const skip = document.querySelector("#skip")
const available = document.querySelector("#available") as HTMLDivElement
let phase = 1
let timer: ExtendableTimeout | null
let timer: ExtendableTimeout | null = null
const getTimeout = () => 2 ** phase * 1000
const message = (command: String, extra?: object) =>
(iframe as HTMLIFrameElement)?.contentWindow?.postMessage(
JSON.stringify({ method: command, ...extra }),
"*"
"https://w.soundcloud.com"
)
const playVideo = () => {
message("seekTo", { value: 0 })
message("setVolume", { value: 30 })
message("play")
if (timer == null) {
@ -86,19 +87,22 @@ import "../styles/index.css"
timer = null
}, getTimeout())
} else {
message("seekTo", { value: 0 })
// message("seekTo", { value: 0 })
message("play")
}
}
iframe?.addEventListener("load", () => {
setTimeout(() => {
window.addEventListener("message", (event) => {
let data = JSON.parse(event.data)
if (data.method === "ready") {
message("setVolume", { value: 0 })
message("play")
}, 300)
message("pause")
message("setVolume", { value: 30 })
}
})
play?.addEventListener("click", playVideo)
skip?.addEventListener("click", () => {
if (phase >= 4) return alert("FAIL!!!!")
phase += 1
@ -109,7 +113,7 @@ import "../styles/index.css"
if (timer == null) {
playVideo()
} else {
timer.extend(getTimeout())
timer?.extend(getTimeout())
}
})
</script>

View file

@ -1,11 +1,28 @@
#music {
position: absolute;
visibility: hidden;
bottom: 0;
iframe {
width: 20px;
height: 20px;
scale: 3;
border: none;
opacity: 0;
}
#play {
position: relative;
display: grid;
cursor: pointer;
&:hover {
filter: brightness(80%);
}
& > .fake-button {
pointer-events: none;
}
& > * {
grid-area: 1 /1;
justify-self: center;
align-self: center;
}
}
#bar {

View file

@ -38,15 +38,16 @@ main {
align-items: center;
}
button {
button,
.fake-button {
--border-radius: 2rem;
position: relative;
background: white;
border: none;
border-radius: var(--border-radius);
padding: 0.2rem 1rem;
margin: 1rem;
padding: 0.2rem;
margin: 0 1rem;
display: flex;
justify-content: center;
@ -62,7 +63,7 @@ button {
}
}
button::before {
:is(button, .fake-button)::before {
--border-size: 5px;
content: "";
border-radius: var(--border-radius);