JS Music Player

Category: Vanilla JavaScript


Problem

A music band wants to showcase their music on their website to sell it, but without giving it away for free. Their previous player was built on Flash Player, which is no longer supported. Additionally, available free JS music player templates didn’t allow for switching albums. Building a new player in JavaScript would provide more flexibility, features, and longevity.


Action

Using the new HTML5 <audio> element, songs can be loaded dynamically with JavaScript. The audio API allows for creating custom controls using JS and CSS. By setting up variables based on the MP3 file names, I was able to create arrays to populate the song list, album titles, album art, and the MP3 files themselves.


Result

The final product is a responsive player that is more visually appealing and feature-rich than the original. For instance, users can now view the inside cover art by clicking on the album’s cover. Since the player is built on native web standards, it should stand the test of time and be easier to update in the future.


Likes: 6 ❤️