Embed API
Javascript API
Contents
Overview
The Streampad Javascript API allows developers to control the Streampad player via Javascript. Developers can play and queue songs, play and pause the player, receive events and perform other useful functions.
Getting Started
In order to make use of the API, Streampad must be present on the page. You can get it here.
Operations
Functions
SPAPI.play():Void
Plays the currently cued/loaded song.
SPAPI.pause():Void
Pauses the currently cued/loaded song.
SPAPI.previous():Void
Plays the previous song in the play queue.
SPAPI.next():Void
Plays the next song in the play queue.
SPAPI.queue():Number
Returns the current queue number for the play queue. (Starts at 0).
SPAPI.queue(n:Number):Void
Sets the play queue to n. (Starts at 0).
SPAPI.total():Number
Returns the number of songs in the play queue.
SPAPI.state():Number
Returns the current state of the player. Possible values are paused (0), playing (1).
SPAPI.song():Object
Returns the current song that is playing. Object will have these properties: songTitle, artist, album, imageUrl (link to album cover art), sourceUrl (link to page containing song), queue (number this song is in the play queue).
SPAPI.add(songTitle:String, artist:String, album:String, enclosure:String, sourceUrl:String, imageUrl:String, share:Boolean):Void
Adds a song to the play queue. Null must be passed in for any missing values. enclosure refers to the url of the song file. Must be in mp3 or aac format. sourceUrl refers to the page containing the song file. imageUrl refers to the url of cover art associated with the song. share refers to if the enclosure could be shared. Default is true.
SPAPI.skip(n:Number):Void
Immediately play the nth song in the play queue. (Queue starts at 0).
SPAPI.start():Void
Starts the player from its initialized state. Equivalent to a user clicking on the player. Do not call this until the player is ready. You can determine this by listening for the onInit event or the onStreampadPlayerReady special event.
SPAPI.clear():Void
Clears the play queue.
SPAPI.hide():Void
Hide the player. The player becomes invisible but all functions still work.
SPAPI.show():Void
Show the player. The player becomes visible from an invisible state.
SPAPI.visible():Boolean
Returns the current visibility of the player.
SPAPI.addEventListener(event:String, listener):Void
Adds a listener function for the specified event. The listener is a reference to a function.
SPAPI.removeEventListener(event:String, listener):Void
Removes a previously added listener function for the specified event. The listener is a reference to a function.
Events
onInit
This event is fired when the player is fully loaded and the API is ready to receive calls.
onStart
This event is fired when the user clicks on the player in its initialized state or when the start function is called.
onSongChange
This event is fired whenever the current song playing changes. The listener will receive an object with these properties: songTitle, artist, album, imageUrl (link to album cover art), sourceUrl (link to page containing song), queue (number this song is in the play queue), total (number of songs in the play queue).
onStateChange
This event is fired whenever the player's state changes. Possible values are paused (0), playing (1).
onQueueChange
This event is fired whenever songs are added to or deleted from the play queue. The listener will receive a number with the total songs in the play queue. If multiple songs are added within 1000 milliseconds of each other, only one event will fire when the addition is complete.
onQueueEnd
This event is fired when the player has finished playing the last song in the play queue.
Special Events
onStreampadPlayerReady
Called when the player is fully loaded and the API is ready to receive calls. The listener will receive an SPAPI object that can be used to make API calls. It is not necessary to listen for this event, but may be helpful if you are loading the player asynchronously.