DEV Community

Discussion on: How to create Music player with pure HTML, CSS, JS

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
 
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
 
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