DEV Community

Cover image for How to create Music player with pure HTML, CSS, JS

How to create Music player with pure HTML, CSS, JS

Modern Web on September 04, 2021

Hello, Today we'll see, how we can easily create a music player using HTML, CSS and JS only. No other library. Our music player has modern looking ...
Collapse
 
joshuaamaju profile image
Joshua Amaju

Why not listen for timeupdate event on the audio element instead of using setInterval.

Collapse
 
tgkprog profile image
Tushar Kapila

Yes for end of song seems like a better way. Especially long songs, more deviation

Collapse
 
themodernweb profile image
Modern Web

Well I didn't knew about that. Thanks for telling this event☺️

Collapse
 
joshuaamaju profile image
Joshua Amaju

It's best to consult the doc for stuff like that

Collapse
 
jamesthomson profile image
James Thomson

I would also suggest tracking the play/pause state against a variable instead of relying on css classes to determine the current state.

Collapse
 
themodernweb profile image
Modern Web

Yup! We can use music.paused as a condition instead of checking for play class both will work☺️

Collapse
 
happyman001144 profile image
Happyman001144

Hi, I am new to HTML/CSS and am creating this project, however the "play" button is in the top left hand side of the container and not the centre, despite me checking the code multiple times I can not figure out why, and my code is exactly the same as yours, any suggestions would be appreciated!

The problem: cdn.discordapp.com/attachments/904...

Code: cdn.discordapp.com/attachments/904...

Collapse
 
dougbug98 profile image
dougbug98 • Edited

The pre and nxt buttons don't even show up exactly how your's shows up. For me they are just very narrow white lines. Where did you get those images from?

Collapse
 
themodernweb profile image
Modern Web

I created those arrows while designing the music player in figma. But you can use font awesome or you can download arrow image from google

Collapse
 
dougbug98 profile image
dougbug98 • Edited

Oh ok coo, I gotta check out figma. I actually went to Google and looked through the images but then I stopped and thought to myself that images from there won't work for the button. Also if you don't mind answering how do you memorize sush very long lines of code across different languages? It reminds me of really long math problems. It just seems like so much to memorize especially all the different numbers for the sizes of the various elements.

Thread Thread
 
themodernweb profile image
Modern Web

No programming is not about memorizing things. I don't memorize any line. Its just practice which made everything easy for us. If you are talking about how I record my tutorial in that case I use a second screen which show me what to code. So there is no memorizing 😅

Collapse
 
dermasajikun profile image
dermasajikun • Edited

I want to ask, to make a list of songs like rytmp3 is it also possible to make it like the way above?