Public Functions

There are a variety of public functions that AmplitudeJS exposes to the user. These methods allow the user to change config variables, add new songs, play now, etc.

Bind New Elements

The bind new elements function should be called whenever a new song element is added to the page. This will bind all of the event handlers for that element.

Amplitude.bindNewElements()

Get Active Playlist

This method will return the key of the active playlist.

Amplitude.getActivePlaylist()

Get Playback Speed

Returns the current playback speed for the player.

Amplitude.getPlaybackSpeed()

Get Repeat

Returns the state of the global repeat status for the player.

Amplitude.getRepeat()

Get Repeat Playlist

Returns the state of the repeat status for the playlist.

Amplitude.getRepeatPlaylist( playlistKey )

Get Shuffle

Returns the current state of the global shuffle status for the player.

Amplitude.getShuffle()

Get Shuffle Playlist

Returns the state of the shuffle flag for a playlist.

Amplitude.getShufflePlaylist( playlistKey )

Set Shuffle

Sets the global shuffle state for AmplitudeJS.

Amplitude.setShuffle()

Set Shuffle Playlist

Sets the shuffle state for a playlist.

Amplitude.setShufflePlaylist( playlistKey )

Set Repeat

Sets the global repeat status for AmplitudeJS

Amplitude.setRepeat()

Set Repeat Song

Sets the global state to determine if we should repeat the individual song upon completion.

Amplitude.setRepeatSong()

Set Repeat Playlist

Sets the repeat for the playlist. This will toggle the playlist repeat status.

Amplitude.setRepeatPlaylist( playlistKey )

Get Default Album Art

Returns the default album art URL set in the player.

Amplitude.getDefaultAlbumArt()

Set Default Album Art

Sets the default album art for the player to the URL provided.

Amplitude.setDefaultAlbumArt( url )

Set Debug

To change the debug mode setting, you can call the setDebug method any time and start to receive data about the state of the player or turn off debugging.

Amplitude.setDebug( {bool} );

Get Active Song Metadata

Returns the active song's metadata as a JSON object.

Amplitude.getActiveSongMetadata();

Get Song By Index

Returns a song's metadata at a specific index.

Amplitude.getSongByIndex( {index} );

Get Song At Playlist Index

Returns a song at a playlist's index.

Amplitude.getSongAtPlaylistIndex( {playlistIndex}, {index} );

Add Song

Adds a song to the AmplitudeJS player. You will need to write a method yourself to add the visual side of things to fit your custom design, and then call the bindNewElements() method to make sure it works.

This method returns the index of the song added to the player.

Amplitude.addSong( {song_object} );

Add Song To Playlist

Adds a song to a specific playlist within AmplitudeJS. Once the song is added you will need to update the visual side of the player yourself. After you update the visual side, run the Amplitude.bindNewElements() method to make sure the functionality is there for the new element.

Amplitude.addSongToPlaylist( songObject, playlistKey )

Remove Song

Removes a song from the global song array. You will have to remove the containing element by yourself.

Amplitude.removeSong( indexOfSong )

Remove Song From Playlist

Removes a song from a playlist. You will have to update the visual side by yourself.

Amplitude.removeSongFromPlaylist( indexOfSongInPlaylist, playlistKey )

Play Song At Index

Plays whatever song is set in the config at the specified index.

Amplitude.playSongAtIndex( songIndex )

Play Playlist Song At Index

Plays the song in a playlist at the specified index.

Amplitude.playPlaylistSongAtIndex( playlistIndex, playlistKey )

Play Now

In AmplitudeJS 2.0 this was referred to as 'Dynamic Mode'. Now you can just pass a song to AmplitudeJS and it will automatically play. If there are visual elements, then they will sync as well.

Amplitude.playNow( {song_object} );

Play

This simply plays whatever song is active.

Amplitude.play()

Pause

This simply pauses whatever song is active.

Amplitude.pause()

Next

Plays the next song either in the playlist or globally.

Amplitude.next( playlistKey = null )

Prev

Plays the previous song either in the playlist or globally.

Amplitude.prev( playlistKey = null )

Get Audio

This returns the actual audio element. This is mainly used for writing extensions but exposes the core of AmplitudeJS. This returns the audio element used by AmplitudeJS.

Amplitude.audio()

Get songs

This method returns all of the songs defined in AmplitudeJS. It can be used for a variety of different functions. It's extremely helpful if you are AJAX loading songs and want to see the contents of the song array.

Amplitude.getSongs()

Get Songs In Playlist

This method returns all of the songs in a playlist. Since the user defines a playlist with a key and the indexes of the songs, this will map the keys to the songs and return all of the songs in the playlist.

Amplitude.getSongsInPlaylist( playlistKey )

Get Songs State

This method returns the current order of the songs. It can be used for determining what song is next. If shuffle is on, it will return the shuffled list of songs.

Amplitude.getSongsState()

Get Songs State Playlist

This method returns the current order of the songs in a playlist. If needed this can be used to determine the next song in a playlist. This accounts for whether the playlist has been shuffled or not.

Amplitude.getSongsStatePlaylist( playlist )

Get Active Index

This method returns the index of the active song in the songs array.

Amplitude.getActiveIndex()

Get Active Index State

This method returns the index of the active song in the songs array but accounts for if shuffle has been enabled or not.

Amplitude.getActiveIndexState()

Get Version

This method returns the version of AmplitudeJS being used.

Amplitude.getVersion()

Get Buffered

This method returns the buffered percentage of the now playing song. This can be used to show how much of the song has been buffered and ready to be played.

Amplitude.getBuffered()

Get Song Played Percentage

This method returns the percentage of the song played. When implementing a 3rd party tracking element, you can set the percentage of the element to the percentage played of the song.

Amplitude.getSongPlayedPercentage()

You can combine this method with the time_update callback and whenever the time updates your method can call Amplitude.getSongPlayedPercentage() and you can set your tracking element correctly.

Get Song Played Seconds

This method returns the current seconds the user is into the song.

Amplitude.getSongPlayedSeconds()

Get Song Duration

Returns the duration of the current song.

Amplitude.getSongDuration()

Set Song Played Percentage

This method allows you to set the percentage of the active song. The method accepts a float between 0 and 100 for the percentage of the song to be set to.

Amplitude.setSongPlayedPercentage( percentage )

Skip To

Allows the user to skip to a specific location in the song whether that song is in a playlist or not.

Amplitude.skipTo( seconds, songIndex, playlist = null )

Set Delay

If you have multiple songs that your player is using you can change the amount of time you have as a delay between the songs. When one song ends, what is set will be the amount of time delayed before the next song starts.

Amplitude.setDelay( milliseconds )

Set Meta Data

You can set the meta data for any song in your song objects. This is helpful if you are doing a live stream and have a call back that returns the information of what song is currently playing.

Amplitude.setMetaData( index, metaData )

The first parameter index is the index of the song in the songs array you are setting the meta data for. The metaData is an object that contains meta data similar to a song object. The keys that get passed will be updated on the song object at the index. The only key that can not be updated is the url.