title | meta | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Public Functions - AmplitudeJS Documentation |
|
Returns the current AmplitudeJS configuration.
Amplitude.getConfig();
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()
This method will return the key of the active playlist.
Amplitude.getActivePlaylist()
Returns the current playback speed for the player.
Amplitude.getPlaybackSpeed()
Returns the state of the global repeat status for the player.
Amplitude.getRepeat()
Returns the state of the repeat status for the playlist.
Amplitude.getRepeatPlaylist( playlistKey )
Returns the current state of the global shuffle status for the player.
Amplitude.getShuffle()
Returns the state of the shuffle flag for a playlist.
Amplitude.getShufflePlaylist( playlistKey )
Sets the global shuffle state for AmplitudeJS.
Amplitude.setShuffle( shuffleState )
Sets the shuffle state for a playlist.
Amplitude.setShufflePlaylist( playlistKey, shuffleState )
Sets the global repeat status for AmplitudeJS
Amplitude.setRepeat( repeatState )
Sets the global state to determine if we should repeat the individual song upon completion.
Amplitude.setRepeatSong( repeatSongState )
Sets the repeat for the playlist.
Amplitude.setRepeatPlaylist( playlistKey, repeatState )
Returns the default album art URL set in the player.
Amplitude.getDefaultAlbumArt()
Sets the default album art for the player to the URL provided.
Amplitude.setDefaultAlbumArt( url )
Returns the URL of the default album art for the player.
Amplitude.getDefaultAlbumArt()
Gets the default art for a playlist.
Amplitude.getDefaultPlaylistArt()
Sets the default playlist art.
Amplitude.setDefaultPlaylistArt( url )
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} );
Returns the active song's metadata as a JSON object.
Amplitude.getActiveSongMetadata();
Gets the active playlist's metadata as a JSON object.
Amplitude.getActivePlaylistMetadata();
Returns a song's metadata at a specific index.
Amplitude.getSongAtIndex( {index} );
Returns a song at a playlist's index.
Amplitude.getSongAtPlaylistIndex( {playlistIndex}, {index} );
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} );
Adds a song to the beginning of the AmplitudeJS player. After pre-pending the song, you will have to bindNewElements() method to make sure that any visuals are updated as well.
This method returns the index of the song added to the player.
Amplitude.prependSong( {song_object} );
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 )
Removes a song from the global song array. You will have to remove the containing element by yourself.
Amplitude.removeSong( indexOfSong )
Removes a song from a playlist. You will have to update the visual side by yourself.
Amplitude.removeSongFromPlaylist( indexOfSongInPlaylist, playlistKey )
Plays whatever song is set in the config at the specified index.
Amplitude.playSongAtIndex( songIndex )
Plays the song in a playlist at the specified index.
Amplitude.playPlaylistSongAtIndex( playlistIndex, playlistKey )
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} );
This simply plays whatever song is active.
Amplitude.play()
This simply pauses whatever song is active.
Amplitude.pause()
This simply stops whatever song is active.
Amplitude.stop()
Plays the next song either in the playlist or globally.
Amplitude.next( playlistKey = null )
Plays the previous song either in the playlist or globally.
Amplitude.prev( playlistKey = null )
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.getAudio()
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()
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 )
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()
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 )
This method returns the index of the active song in the songs array.
Amplitude.getActiveIndex()
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()
This method returns the version of AmplitudeJS being used.
Amplitude.getVersion()
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()
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.
This method returns the current seconds the user is into the song.
Amplitude.getSongPlayedSeconds()
Returns the duration of the current song.
Amplitude.getSongDuration()
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 )
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 )
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 )
Gets the current delay between songs in milliseconds.
Amplitude.getDelay();
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.setSongMetaData( 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
.
You can set the metadata for the playlist. Similar to the songs object, you can do it for a playlist object.
Amplitude.setPlaylistMetaData( playlist, metaData )
The first argument playlist
is the key of the playlist we are setting the meta data for and the second object metaData
is the object containing all of the keys we are updating.
Returns the Web Audio API Analyser. This allows for the user to bind to the active audio through the web audio API.
Amplitude.getAnalyser()
Returns the current state of the player whether it's playing
, paused
, or stopped
.
Amplitude.getPlayerState()
This method allows you to add a playlist to AmplitudeJS. To do this, you need a unique key for your playlist, the data describing your playlist such as title
, author
, etc. and an array of song objects for your playlist.
Amplitude.addPlaylist( key, data, songs );
The first argument is the key
. Remember this is a JSON key and should be formatted as such.
The second argument is all of the data describing the playlist such as name
, title
, author
, etc. in the form of a JSON object.
Finally, the third argument is an array of song objects. These are the songs that will be added to the playlist.
The other way to register a visualization is through the public Amplitude.registerVisualization( visualization, preferences )
method. The first parameter being the object included with the visualization file and the second parameter being a JSON object containing any of the parameters needed to overwrite defaults provided by the visualization.
Amplitude.registerVisualization( visualization, preferences );
You can set the global visualization through the public method like this:
Amplitude.setGlobalVisualization( visualizationKey );
You can set the visualization through the public facing method like this:
Amplitude.setPlaylistVisualization( playlist_key, visualization_key );
You can set the visualization for an individual song like so:
Amplitude.setSongVisualization( songIndex, visualizationKey );
You can set the visualization for an individual song in a playlist using:
Amplitude.setSongInPlaylistVisualization( playlistKey, songIndex, visualizationKey );