Jukebox
Documentation API Demos

API

play(position, force)

Parameters

Description

This function will start playback of the given spritemap entry.
You can pass through either a value of a time position in seconds (that is inside a defined sprite entry) or an id of a sprite entry.

The sprite entry id is the preferred and fastest way to play.

Example

	// var player = new jukebox.Player(...);


	player.play('bgmusic'); // faster, sprite entry's id
	player.play(12.34); // slower, will search for matching sprite entry
	

stop()

Parameters

This method requires no parameters.

Description

This function will stop playback on the origin jukebox.Player instance.
It will reset the position of the stream to the beginning.

Example

	// var player = new jukebox.Player(...);


	player.play('bgmusic');


	// will stop playback after 2 seconds
	window.setTimeout(function() {
		player.stop();
	}, 2000);
	

pause()

Parameters

This method requires no parameters.

Description

This function will pause playback of the jukebox.Player instance.
It will save the current position of the stream, so you can resume() it later.

Example

	// var player = new jukebox.Player(...);


	player.play('effect');


	// will pause playback after 2 seconds
	window.setTimeout(function() {
		player.pause();
	}, 2000);
	

resume()

Parameters

This method requires no parameters.

Description

This function will resume playback of the jukebox.Player instance.
It will start playback at the last cached position (of a pause() call).
If no position was cached before, it will start from the current position of the stream.

Example

	// var player = new jukebox.Player(...);


	player.play('effect');


	// will pause playback after 2 seconds
	window.setTimeout(function() {
		player.pause();
	}, 2000);


	// will resume playback after 4 seconds
	window.setTimeout(function() {
		player.resume();
	}, 4000);
	

getVolume()

Parameters

This method requires no parameters.

Description

This function returns (Float) the current volume (min: 0, max: 1.0) of the jukebox.Player instance.

Example

	// var player = new jukebox.Player(...);


	player.setVolume(0.3);


	// Log the current volume to the console
	console.log(player.getVolume());
	

setVolume(volume)

Parameters

Description

This function will set the volume to the given value.

Important: Some environments like iOS have no support for modifying the volume

Example

	// var player = new jukebox.Player(...);


	// set volume initially to 30% and start playback
	player.setVolume(0.3);
	player.play('effect');


	// set volume to 100% after 2 seconds
	window.setTimeout(function() {
		player.setVolume(1.0);
	}, 2000);
	

getCurrentTime()

Parameters

This method requires no parameters.

Description

This function returns (Float) the current position (in seconds) of the jukebox.Player instance.

Example

	// var player = new jukebox.Player(...);


	player.play('effect');

	// Log the start position of the sprite entry to the console
	// 200ms timeout lets the jukebox.Manager's loop correct the stream position
	window.setTimeout(function() {
		console.log('start: ' + player.getCurrentTime());
	}, 200);


	// Do it again after 2 seconds
	window.setTimeout(function() {
		console.log('after 2 seconds: ' + player.getCurrentTime());
	}, 2000);
	

setCurrentTime(position)

Parameters

Description

This function returns (Boolean) true if the stream was ready and the position was set. False otherwise.

It will try to set the current position of the jukebox.Player stream.
It may fail if the stream is not ready for that, e.g. if download is still in progress or the background process is not ready for playback.

Example

	// var player = new jukebox.Player(...);


	player.play('effect');


	// Log the start position of the sprite entry to the console
	// 200ms timeout lets the jukebox.Manager's loop correct the stream position
	window.setTimeout(function() {

		console.log('start: ' + player.getCurrentTime());

		player.setCurrentTime(7.00);
		console.log('after setCurrentTime call: ' + player.getCurrentTime());

	}, 200);


	// Do it again after 2 seconds
	window.setTimeout(function() {
		console.log('after 2 seconds: ' + player.getCurrentTime());
	}, 2000);