YAHOO MediaPlayer API 

The Yahoo! WebPlayer API is currently a work in progress and subject to change. All efforts will be made to preserve backwards compatibility, but this is not guaranteed.

Class YAHOO.MediaPlayer

The main class for the application programmer's interface for the YAHOO Media Player

Events

onAPIReady

onAPIReady ( )
This event is fired when YAHOO.MediaPlayer API is initialized and ready to be used by third party applications.
This event should be the first event that 3rd party applications register to only after this event is triggered can the Media Player API be accessed safely

onMediaUpdate

onMediaUpdate ( )
Event fired when a media object is updated with properties like title, album etc.
The argument passed to the subscriber function is the media object that has been updated.

onPlaylistUpdate

onPlaylistUpdate ( )
This event is fired any time the playlist is updated.
The argument passed to the subscriber function is the playlist array.

onProgress

onProgress ( )
This event is fired when the progress is updated when media is playing.
The argument passed to the subscriber function is of the form {elapsed: "elapsed time milliseconds", duration: "duration of the media in milliseconds"}

onTrackComplete

onTrackComplete ( )
Event fired when entire media is finished playing.
The argument passed to the subscriber function is of the form {mediaObject:"the media object that just finished playing"}

onTrackPause

onTrackPause ( )
Event fired when media is paused.
The argument passed to the subscriber function is of the form {mediaObject:"the media object being paused"}

onTrackStart

onTrackStart ( )
Event fired when media starts playing.
The argument passed to the subscriber function is of the form {mediaObject:"the media object being played"}

Methods

addTracks

void addTracks ( domElem , index , clear )
API function to add tracks to the playlist
Parameters:
domElem <object> HTML DOM element (possibly contains media anchor tags)
index <number> Location in the playlist where the tracks are to be inserted. null means append - else insert
clear <boolean> clear playlist before adding
Returns: void

getMetaData

Object getMetaData ( index )
API function to get metadata.
Parameters:
index <Number> position in the playlist array for which you need metadata. If null, return current playing metadata
Returns: Object
Return the metadata for the current media

getPlayerState

Number getPlayerState ( )
API function to get media state.
Returns: Number
Return a number representing the state of the current media.
STOPPED: 0, PAUSED: 1, PLAYING: 2,BUFFERING: 5, ENDED: 7

getPlayerViewState

Number getPlayerViewState ( )
API function to get the current visual state of the player
Returns: Number
Return a number representing the visual state of the player
0:minimized, 1: maximized, -1 hidden

getPlaylistCount

Number getPlaylistCount ( )
API function to return the number of songs in the playlist. Returns -1 if the call fails.
Returns: Number
Return the number of songs in the playlist

getTrackDuration

Number getTrackDuration ( )
API function to return the track duration.
Returns: Number
Return the track duration in seconds

getTrackPosition

Number getTrackPosition ( )
API function to return the track position.
Returns: Number
Return the track position in seconds

getVolume

Number getVolume ( )
API function to return the volume.
Returns: Number
Return the media player volume as a float between 0 and 1.0

next

void next ( )
API function to move to the next media in the playlist. If the current media is playing, the next media will start playing.
Returns: void

pause

void pause ( )
API function to pause media playback
Returns: void

play

void play ( mediaObj , seek )
API function to play a media object
Parameters:
mediaObj <Object> media object
seek <Number> seek position where playback should begin
Returns: void

previous

void previous ( )
API function to move to the previous media in the playlist. If the current media is playing, the previous media will start playing.
Returns: void

setPlayerViewState

void setPlayerViewState ( viewState )
API function to set the visual state of the player
Parameters:
viewState <number> A number representing the visual state of the player,0:minimized, 1: maximized, -1 hidden
Returns: void

setVolume

void setVolume ( vol )
API function to set the volume.
Parameters:
vol <Number> the new volume to be set. Has to be a float between 0 and 1.0
Returns: void

stop

void stop ( )
API function to stop media playback
Returns: void

setQueueViewState

void setQueueViewState ( viewState )
API function to set the visual state of the playlist queue
Parameters:
viewState <number> A number representing the visual state of the playlist queue,0:minimized, 1: maximized
Returns: Boolean
Returns true when setting the state is done successfully, false otherwise

getQueueViewState

Number getQueueViewState ( )
API function to get the current visual state of the playlist queue
Returns: Number
Return a number representing the visual state of the playlist queue
0:minimized, 1: maximized

toString

String toString ( )
Returns the string representation of the class YAHOO.MediaPlayer
Returns: String
Return the string representation of the class

Yahoo Media Player Parameters

autoplay

Setting autoplay to true will start the first song automatically after the Yahoo Media Player loads.
Default value is false

autoadvance

Setting autoadvance to false will tell the Yahoo Media Player to NOT advance to the next track automatically once the current track finishes playing.
Default value is true

parse

Setting parse to false will tell the Yahoo Media Player to NOT scrape the page for media links once it loads
Default value is true

playlink

Setting parse to false will mean that clicking on a media link will NOT play it in the Yahoo Media Player. The browser will decide the playback technology.
Default value is true

displaystate

Setting the displaystate to 0 will load the Yahoo Media Player in minimized state.
Setting the displaystate to 1 will load the Yahoo Media Player in maximized state.
Setting the displaystate to 3 will load the Yahoo Media Player in no ui state.
Setting the displaystate to -1 will load the Yahoo Media Player in hidden state.
Default value is 0

volume

Sets the default volume. Expects a floating number between 0.0 and 1.0.
Default value is 0.5

defaultalbumart

Sets the url to the default album art image.
Default value is a url to generic album art image for the Yahoo Media Player.

amazonid

Allows a website author to specify an amazon id for the buy link on the songs

Using the API on a third party website:

<script type="text/javascript">
    var YMPParams =
    {
        autoplay:true,
        volume:0.5,
        defaultalbumart:'http://somedomain.com/path/someimage.gif'
    }
</script>

<script type="text/javascript" src="http://mediaplayer.yahoo.com/latest">
    /* This will include the yahoo media player on the page */
</script>

<script type="text/javascript">

    var apiReadyHandler = function ()
    {
        /* Once API ready handler is invoked, YAHOO.MediaPlayer class can be accessed safely */
        /* For example: Add other event listeners **/
        YAHOO.MediaPlayer.onPlaylistUpdate.subscribe(onPlaylistUpateHandler)
    }

    var onPlaylistUpateHandler = function (playlistArray)
    {
        /* Handler for onPlaylistUpdate event */
        alert(" playlist count = " + YAHOO.MediaPlayer.getPlaylistCount())
    }

    YAHOO.MediaPlayer.onAPIReady.subscribe(apiReadyHandler);

</script>

Copyright © 2008 Yahoo! Inc. All rights reserved.