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" import "../styles/index.css"
--- ---
<Layout <Layout>
><iframe <div id="play">
id="music" <iframe
width="100%" title="SoundCloud Play Button"
height="300"
allow="encrypted-media *;"
src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/soundcloud%253Atracks%253A2196321083" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/soundcloud%253Atracks%253A2196321083"
></iframe> ></iframe>
<button id="play">
<span class="fake-button">
<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">
<path <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" 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> ></path>
</svg> </svg>
</button> </span>
</div>
<section id="bar"> <section id="bar">
<div id="bars"> <div id="bars">
<div></div><div></div><div></div> <div></div><div></div><div></div>
@ -60,23 +61,23 @@ import "../styles/index.css"
} }
} }
const iframe = document.querySelector("#music") const iframe = document.querySelector("iframe")
const play = document.querySelector("#play")
const skip = document.querySelector("#skip") const skip = document.querySelector("#skip")
const available = document.querySelector("#available") as HTMLDivElement const available = document.querySelector("#available") as HTMLDivElement
let phase = 1 let phase = 1
let timer: ExtendableTimeout | null let timer: ExtendableTimeout | null = null
const getTimeout = () => 2 ** phase * 1000 const getTimeout = () => 2 ** phase * 1000
const message = (command: String, extra?: object) => const message = (command: String, extra?: object) =>
(iframe as HTMLIFrameElement)?.contentWindow?.postMessage( (iframe as HTMLIFrameElement)?.contentWindow?.postMessage(
JSON.stringify({ method: command, ...extra }), JSON.stringify({ method: command, ...extra }),
"*" "https://w.soundcloud.com"
) )
const playVideo = () => { const playVideo = () => {
message("seekTo", { value: 0 })
message("setVolume", { value: 30 }) message("setVolume", { value: 30 })
message("play") message("play")
if (timer == null) { if (timer == null) {
@ -86,19 +87,22 @@ import "../styles/index.css"
timer = null timer = null
}, getTimeout()) }, getTimeout())
} else { } else {
message("seekTo", { value: 0 }) // message("seekTo", { value: 0 })
message("play") message("play")
} }
} }
iframe?.addEventListener("load", () => { window.addEventListener("message", (event) => {
setTimeout(() => { let data = JSON.parse(event.data)
if (data.method === "ready") {
message("setVolume", { value: 0 })
message("play") message("play")
}, 300) message("pause")
message("setVolume", { value: 30 })
}
}) })
play?.addEventListener("click", playVideo)
skip?.addEventListener("click", () => { skip?.addEventListener("click", () => {
if (phase >= 4) return alert("FAIL!!!!") if (phase >= 4) return alert("FAIL!!!!")
phase += 1 phase += 1
@ -109,7 +113,7 @@ import "../styles/index.css"
if (timer == null) { if (timer == null) {
playVideo() playVideo()
} else { } else {
timer.extend(getTimeout()) timer?.extend(getTimeout())
} }
}) })
</script> </script>

View file

@ -1,11 +1,28 @@
#music { iframe {
position: absolute; width: 20px;
visibility: hidden; height: 20px;
bottom: 0; scale: 3;
border: none;
opacity: 0;
} }
#play { #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 { #bar {

View file

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