Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
a Summer day - @744.00
Activity rating: Four Stars Posts & Arts: 75/1k.beats Random | Recent Posts | Guild Recents
News: There's a great big indie web tomorrow! :smile: Guild Events: There are no events!

+  MelonLand Forum
|-+  Life & The Web
| |-+  ✁ ∙ Web Crafting
| | |-+  Playable Music Button


« previous next »
Pages: [1] Print Embed
Author Topic: Playable Music Button  (Read 212 times)
willyonilly
Newbie ⚓︎
*
View Profile WWW


BILLYBILLY
⛺︎ My Room

Artifacts:
Joined 2026!
« on: a Summer day » Embed

Hello! I finally got a music button working and wanted to share the code!!! I have this in a container on top of an image, so if you want it separate, you might have to tinker with it some.
 
You'll add this inside your STYLE tag:

        .music-button {
            position: absolute;
            top: 50px;       /* Adjust this number to move the button up or down! */
            left: 50px;      /* Adjust this number to move the button left or right! */
            background: none;
            border: none;
            cursor: pointer;
            z-index: 10;     /* Ensures the button stays on top of the image! */

In your BODY tag above the container, you'll add this. It's your script to make the music play:
 
    <audio id="myMusic" src="MUSIC.MP3"></audio>

    <script>
        function toggleMusic() {
            var audio = document.getElementById("myMusic");
            var img = document.getElementById("buttonImage");
            if (audio.paused) {
                audio.play();
                img.src = "YOUR_PAUSE_BUTTON.PNG";
            } else {
                audio.pause();
                img.src = "YOUR_PLAY_BUTTON.PNG";
            }
        }
    </script>

Beneath this, add your container! Beneath the container code, you'll add this:

            <button onclick="toggleMusic()" class="music-button">
                <img id="buttonImage" src="YOUR_MUSIC_BUTTON.PNG" alt="Play Music" width="100">
            </button>

All in all, it should look like this! This image, of course, contains my own chosen song + the assets I created!
https://file.garden/anYfh4-1EEBDJOQ2/Screenshot%202026-08-08%20111951.png

Logged

Glory to you and your House!
MrsMoe
Hero Member ⚓︎
*****
View Profile WWWArt


Your friendly neighborhood living dead girl
⛺︎ My Room

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Deviantart Llama!Great Posts PacmanFirst 1000 Members!Joined 2022!
« Reply #1 on: a Summer night » Embed

What exactly should it look like on your webpage once it's implemented?

Logged

https://blinkies.cafe/b/display/0113-autism.gifhttps://blinkies.cafe/b/display/0021-vampirefangs.gifhttps://blinkies.cafe/b/display/0182-halloweencathouse.gifhttps://i.postimg.cc/02L6smjc/ezgif-7-ebef155de1.gifhttps://64.media.tumblr.com/e53076104c8d22ed3d272d62cc8fccfa/88280e3f54890c11-c1/s250x400/aa5c1239ea59888acaa71ad26271790a794ccc5d.gifvhttps://blinkies.cafe/b/display/0138-greenglow.gif
https://i.ibb.co/Lzg2SZj/tumblr-5afbadec7c65089061ba8cfa48b57bc8-469c61aa-100.webphttps://tinyurl.com/yn2v726zhttps://tinyurl.com/39tjbzfmhttps://tinyurl.com/32x3t38jhttps://tinyurl.com/2ybkhmh5https://tinyurl.com/2ue7d945https://tinyurl.com/493hsx5phttps://tinyurl.com/ye28hzrphttps://64.media.tumblr.com/92ec86321325be8fac199fecef8fd7b0/tumblr_ptpl0x7U4o1y8ua8do1_100.gifv
Rubbereon
Full Member ⚓︎
***
View Profile WWWArt


⛺︎ My Room
SpaceHey: Friend Me!
Matrix: Chat!
XMPP: Chat!

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Joined 2025!
« Reply #2 on: a Summer night » Embed

Nice, but have you tried scmplayer or wikplayer before before making a custom widget?  :eyes:

Also bear in mind that music just cannot play automatically, you could maybe before 2020, but now it's required for the user to click on the webpage first before the music would play.

Logged

https://bettysgraphics.neocities.org/images/animals/cat%20695.gifFuzzy fwiendhttps://bettysgraphics.neocities.org/images/animals/cat%20696.gifhttps://bettysgraphics.neocities.org/images/animals/cat%20697.gif
https://rubbereon.nekoweb.org/img/penguin.gifLinux userhttps://rubbereon.nekoweb.org/img/penguin.gif
You can also find me on Comfybox.
willyonilly
Newbie ⚓︎
*
View Profile WWW


BILLYBILLY
⛺︎ My Room

Artifacts:
Joined 2026!
« Reply #3 on: a Summer night » Embed

What exactly should it look like on your webpage once it's implemented?

Mine looks like this: https://file.garden/anYfh4-1EEBDJOQ2/Screenshot%202026-08-08%20135259.png
The big red button is the music player. If tinkered around with, you could probably get it to sit somewhere else - the code I shared is to specifically get it to sit atop another image, but I could try to conjure up some code to have it separate!!!

Logged

Glory to you and your House!
willyonilly
Newbie ⚓︎
*
View Profile WWW


BILLYBILLY
⛺︎ My Room

Artifacts:
Joined 2026!
« Reply #4 on: a Summer night » Embed

Nice, but have you tried scmplayer or wikplayer before before making a custom widget?  :eyes:

Also bear in mind that music just cannot play automatically, you could maybe before 2020, but now it's required for the user to click on the webpage first before the music would play.

I haven't! I usually end up doing things the hard way, LOL. I like to make things difficult for myself. I also am slightly obsessed with everything on my site being Klingon-themed. If I can't customize it to the utmost degree, I just make my own!
Don't worry - I made it that way on purpose! I, myself, always get a little irritated when I have to manually mute an entire site because I don't want to listen to the music that's playing. I prefer to have it be manual to play it!

« Last Edit: a Summer night by willyonilly » Logged

Glory to you and your House!
MrsMoe
Hero Member ⚓︎
*****
View Profile WWWArt


Your friendly neighborhood living dead girl
⛺︎ My Room

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Deviantart Llama!Great Posts PacmanFirst 1000 Members!Joined 2022!
« Reply #5 on: a Summer night » Embed

Mine looks like this: https://file.garden/anYfh4-1EEBDJOQ2/Screenshot%202026-08-08%20135259.png
The big red button is the music player. If tinkered around with, you could probably get it to sit somewhere else - the code I shared is to specifically get it to sit atop another image, but I could try to conjure up some code to have it separate!!!

Cool! I technically already have a music player on my site, but it's regulate to a single page. It'll be cool to have one that follows the user around the site.

Logged

https://blinkies.cafe/b/display/0113-autism.gifhttps://blinkies.cafe/b/display/0021-vampirefangs.gifhttps://blinkies.cafe/b/display/0182-halloweencathouse.gifhttps://i.postimg.cc/02L6smjc/ezgif-7-ebef155de1.gifhttps://64.media.tumblr.com/e53076104c8d22ed3d272d62cc8fccfa/88280e3f54890c11-c1/s250x400/aa5c1239ea59888acaa71ad26271790a794ccc5d.gifvhttps://blinkies.cafe/b/display/0138-greenglow.gif
https://i.ibb.co/Lzg2SZj/tumblr-5afbadec7c65089061ba8cfa48b57bc8-469c61aa-100.webphttps://tinyurl.com/yn2v726zhttps://tinyurl.com/39tjbzfmhttps://tinyurl.com/32x3t38jhttps://tinyurl.com/2ybkhmh5https://tinyurl.com/2ue7d945https://tinyurl.com/493hsx5phttps://tinyurl.com/ye28hzrphttps://64.media.tumblr.com/92ec86321325be8fac199fecef8fd7b0/tumblr_ptpl0x7U4o1y8ua8do1_100.gifv
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF 2.0.19 | SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Forum Guide | Rules | RSS | WAP | Mobile


MelonLand Badges and Other Melon Sites!

MelonLand Project! Visit the MelonLand Forum! Support the Forum
Visit Melonking.Net! Visit the Gif Gallery! Pixel Sea TamaNOTchi
@000 MelonLand Editor Recent Edits Tenement Arcade Want to Login or Join ? Forum Art Hub Chat Webring Web Guides Graphics Catalogue Wiki Newsletters Image Stream
Melon's Sites TamaNotchi Textures PixelSea GifyPet MoMG Ozwomp Online Loom Videos Leaky Webring Melonking
Tools Melon Software ArtHub Embed Maker ML Passports
Outlinks Frutiger Aero Forum Onio Club m15o's Web Services 32Bit Cafe iMood Webrings Internet Phone Book HTML Energy Declarations Hackers & Designers
Zap!
Minecraft: Online
Join: craft.melonking.net