Artifacts Gallery Guilds Search Wiki Login Register

Welcome, Guest. Please login or register. - Thinking of joining?
Autumn, 20 Nov 2026 - @43.69
Forum Activity: Four Stars Random | Recent Posts | Guild Recents
News: :4u: ~~~~~~~~~~~ Guild Events: Noir-vember TTRPG game jam
+  MelonLand Forum
|-+  Da Web Revival
| |-+  ✁ ∙ Web Crafting
| | |-+  ♺ ∙ Snippets & Materials
| | | |-+  FREE Custom music player for YOUR website!!!


« previous next »
Pages: [1] Print Embed
Author Topic: FREE Custom music player for YOUR website!!!  (Read 115 times)
schlime9k
Full Member ⚓︎
***
View Profile WWW


Forever personalising my profile
⛺︎ My Room
StatusCafe: schlime9k
iMood: schlime9k
RSS: RSS

Guild Memberships:
Artifacts:
Visited on Melon's 10th Anniversary!Joined 2025!
« on: Autumn, 17 Nov 2026 @234 » Toggle Font Embed

YO YO! CUSTOM MUSIC PLAYER FOR FREE???

I've been hard at work to make my web-shrine for The Beatles and wanted to have a music player for the page, but I couldn't find any good ones on the net, so I resorted to making one myself. It took way too long and a bit of copying and pasting from other music players that work because I know next-to-nothing about Javascript, but I got it running! Take a look:

https://schlime.online/music-player/

I'll run through some of the HTML and Javascript. The CSS is done but you should be able to make it look however you want, it doesn't HAVE to look like something made in the late 90's...

Step #1. Da HTML
Code
<div id="player">
   <div class="container">
      <div id="player-art">
         <img id="cover" src="">
      </div>

      <div class="inner-container">
         <div class="container">
            <div class="track-title">
               <p id="now-playing"></p>
             </div>
             <button onclick="myFunction()" class="dropdown-button">&#9660;</button>
          </div>
          <div id="dropdown" class="dropdown-content">
             <a href="#" onclick="selectalbum('[Title of Album]'); return false">Album 1</a>
             <a href="#" onclick="selectalbum('[Title of Album 2]'); return false">Album 2</a>
          </div>
Here is the main part of the whole player, you have the album art that has the id of "cover" which is intentionally left blank as to let the javascript put the url of the currently loaded album that you select into the href area. Same thing with the "now-playing" p. In the "dropdown" area, you can have as many dropdowns as you want. The "return false" is very important! For some reason it the button doesn't work unless it's there, at least from my experience.
Code
<div class="playback">
   <button onclick="prevtrack()" title="Previous Track">&#9198;</button>
   <button id="play" onclick="playback()" title="Play / Pause">&#9654;</button>
   <button onclick="nexttrack()" title="Next Track">&#9197;</button>
</div>
                    
<input id="scrubber" type="range" min="0" max="0" value="0" step="1">
<div id="runtime">
   <span id="current-time">0:00</span>
   <span id="duration">0:00</span>
</div>
These are the buttons to play/pause, skip and go back, and also the scrubber. Nothing too crazy here except this "&#9654;" thingy... What is that? Why it's HTML entities of course! Basically, symbols and shapes in HTML need to be written as strings of symbols and numbers such as ones you see above. I use them all the time to place n-dashes (written as &ndash;) and ampersands (written as &amp;). It'll be the same with playback symbols like you see above. That's why it's important for us in the Javascript section to use "innerHTML" instead of the more common "textContent".
The scrubber's pretty simple, and same with the time and duration stuff, make sure to use those exact ID's, they don't need to be <span>s, but I like changing up what kind of text tag I use every now and then.

Step #2. javascript... >:(

You probably can't tell, but I don't like Javascript... But alas, I kinda have to use it.
Code
const albums = {
   "[Title of Album]": {
      cover: "../images/bgs/clouds.png",
      tracks: [
         { title: "Track 01", src: "link-2-track-1-here" },
         { title: "Track 02", src: "link-2-track-2-here" },
         { title: "Track 03", src: "you get the idea.mp3" }
      ]
   },
etc...
This is where you'll put all your music. I labelled it as "albums" because that's how I'm using my music player, but you can put playlists or just single songs on there, it doesn't matter. It also doesn't matter how you format this section, this is just easy on the eyes for me but format it however you like. If you put more than one album/playlist here, make sure the comma is there at the last curly bracket, and if it's the last album, get rid of the comma! It does break everything so yes, it is important!

Code
// all constants you need to make this -- make sure the IDs match
const audio = document.getElementById("music-player");
const cover = document.getElementById("cover");
const nowplaying = document.getElementById("now-playing");
const playbutton = document.getElementById("play");
const scrubber = document.getElementById("scrubber");
const currenttime = document.getElementById("current-time");
const duration = document.getElementById("duration");
            
let currentalbum = "[Title of Album]"; // the album / playlist the page will open on
let currenttrack = 0; // computer thing, track 0 is actually track 1, you get the idea
You can change the IDs if you want, it's not a breaks everything thing but make sure you update the IDs everywhere else if you do change them.

Code
function loadtrack() {
   const track = albums[currentalbum].tracks[currenttrack];
   audio.src = track.src;
   cover.src = albums[currentalbum].cover;
   nowplaying.innerHTML = "Now Playing &mdash; " + track.title;
   scrubber.value = 0;
   currenttime.innerHTML = "0:00";
   duration.innerHTML = "0:00";
}
Everything else imo is pretty self-explanatory by simply looking at the code, but I'll still explain it anyway. This simply loads all the relevant information for what the player needs to show, like what track it is, displaying the "now playing" section, cover, etc.

Code
function formatTime(time) {
   if (!isFinite(time)) return "0:00";
                
   const minutes = Math.floor(time / 60);
   const seconds = Math.floor(time % 60);
                
   return minutes + ":" + String(seconds).padStart(2, "0");
}
audio.ontimeupdate = function() {
   currenttime.innerHTML = formatTime(audio.currentTime);
   scrubber.value = audio.currentTime;
};
audio.onloadedmetadata = function() {
   scrubber.max = audio.duration;
   duration.innerHTML = formatTime(audio.duration);
};
scrubber.oninput = function() {
   audio.currentTime = scrubber.value;
};

This is everything to do with the scrubber and also time/duration stuff. I stole this from somewhere, I forgot where though. I thought I'd put a note in my html about where I got it from but apparently not. Nonetheless, this is not my code.

Step #3. Ctrl+C, Ctrl+V!

Yup! Simply copy and paste the below attachments into your webpage and make the player your own! Hope you enjoy, and do tell us in the comments of this thread if you upgraded the player and how! I'd love to have maybe a "track selector" or have sections in the dropdown to show either playlists or albums!

Cya!
 - schlime <3



* index.html (7.06 kB - downloaded 3 times.)
* musicplayer.css (2.48 kB - downloaded 2 times.)
« Last Edit: Autumn, 18 Nov 2026 @169 by schlime9k » Logged

https://schlime.online/images/buttons/wsw.gif

Artifact Swap: Forum-Posting Extraordinaire!Physical media FOREVA!I met Dan Q on Melonland!GrapesAce Honey
Pages: [1] Print Embed 
« previous next »
 

Melonking.Net © Always and ever was! SMF © 2021 | Privacy Notice | Send Feedback | Supporters ♥ Guide | Rules | Whos a Mod? | 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 Melon
Land
Forum Art Hub Chat Webring Explore Random Recent Tenement Arcade Want to Login or Join ? Web Craft Guide Graphic Catalogue Wiki Help I'm Lost! Link Land Newsletters Image Stream Minecraft: Online
Zap!
Passport Sites tamaNOTchi Asatte Add your site?
Aero Archive Onio Cafe 32 Bit Cafe Status Cafe