onReady

 

Each player has its own "onReady" handler that allows you to be notified when a player is ready and able to be interacted with via Javascript.

When you call the onReady function, you'll set the first argument to the function you want to be "pinged" when the player is ready. You can also include any additional arguments.

When the player is ready your function will be pinged and the first argument will be a reference (handle) to the player, followed by any additional arguments you included.

The onReady functionality can also be leveraged as a player option, however the player option method does not allow for additional arguments. See Example 4 below.

onReady(pingMe, args...)

 

Parameters

pingMe function

The function that will be "pinged" when the player is ready.

args mixed (optional)

Any number of arguments can be sent in. These arguments will be returned to your function.

 

Return Value

A reference (handle) to the player (as first argument), followed by any additional arguments you included.

 

See Also

 

Examples

Example 1

<script>
// Create a new player
var myPlayer = new wimpyPlayer();

// This is as simple as it gets, the "doWhenReady"
// function will execute when the palyer is ready. function doWhenReady(){ alert("ready"); } myPlayer.onReady(doWhenReady);
</script>

 

Example 2

<script>
// Create a new player
var myPlayer = new wimpyPlayer();

// This function is set up to receive one argument (thePlayer).
// Wimpy always sends a reference (handle) to the player as
// the first argument. function doWhenReady(thePlayer){ alert("Player ID: " + thePlayer.id); } myPlayer.onReady(doWhenReady);
</script>

 

Example 3

<script>
// Create a new player
var myPlayer = new wimpyPlayer();

// The first argument will be a reference to the player, aka "handle" aka "Player Object",
// any additional arguments are also returned. function pingMe (playerHandle, arg1, arg2){

playerHandle.setPlaylist("song1.mp3 | song2.mp3"); console.log(playerHandle.id, arg1, arg2); } myPlayer.onReady(pingMe, "foo", "bar");
</script>

 

Example 4

To leverage the same functionality when establishing a player,  add an "onReady" field to the wimpyPlayer options parameter as:

// This function is set up to receive one argument (thePlayer).
function doWhenReady(thePlayer){
	alert(thePlayer.id);
}
new wimpyPlayer({
					onReady : doWhenReady,
					media	: "foo.mp3"
					});