
We will be setting up two sliders that control the seek slider and the volume slider. The loadTrack() method defined above is used for loading the new track. The index is reset to the first track when the index reaches the last track. Similarly, a function nextTrack() handles the loading of the next track and moving the index forward. The index is reset to the last track when the index reaches the first track. The playpause() function handles the actual play/pause control of the track.Ī function prevTrack() handles the loading of the previous track and moving the index backward. These two functions are invoked depending on whether the track is currently playing or not. This is done by using one of the icons from the FontAwesome library and inserting it using innerHTML. The icon of the button also changes back to the play icon.

The pause() method of the HTMLMediaElement API is used for this function. This is done by using one of the icons from the FontAwesome library and inserting it using innerHTML.Ī function pauseTrack() handles the playing of the currently loaded track. The icon of the button also changes to the pause icon. The play() method of the HTMLMediaElement API is used for this function. The effect is animated by using the transition property on the background-color.Ī function playTrack() handles the playing of the currently loaded track.
#SETVOLUME MUSICPLAYER ANDROID UPDATE#
The media element has two event listeners added to it, the first one to update the current seek position and the second one to load the next track when the current track finishes.Ī coloured background is generated by randomising the red, green and blue values used and setting it as a color. The track details are fetched from the array and assigned with the help of the textContent property. The track art is fetched from the array and assigned with the help of the backgroundImage property. The load() method is then used on the audio element to get the track ready. It may be given any path from the filesystem or a URL. The audio element is assigned a new source using its src property. This prevents the jumping of the seek slider while the new track loads. Reset all the values of the previous trackĪ resetValues() function is created which handles the resetting of the duration value and the slider to their initial values before a new track starts.To load a track, a function loadTrack() is defined which handles the following things: Each of the tracks can then be accessed using its track index. These objects contain properties like the name, artist, image and path to the track. Step 2: Loading a new track from the tracklistĪll the tracks that have to be played are defined in the tracklist as objects.
#SETVOLUME MUSICPLAYER ANDROID HOW TO#
:max_bytes(150000):strip_icc()/musicplayerequalizeryoutube-5bc8d20a46e0fb0026c8db37.png)
