appendPlaylist(listOrURL, atIndex, startPlaying)



listOrURL mixed

Can be a URL to any external media file or playlist. Or JSON, raw JSON (string), or a Javascript Array. See Playlist Overview for more information on acceptable playlist formats.

Default Value: Must exists

atIndex integer

Specifies the point at which to insert the new item(s) into the list. The index specified is a "1" based index, (as opposed to a classic javascript array, which is "0" based).

For example, to insert an item at as the second item in the playlist, set this argument to 2

If this value is left blank or set to null, Wimpy will put the item at the end of the current list by default.

If playlist sorting us being used, this parameter will not work as expected! Because whena track is added, the player sorts the playlist immediately. So for example if you set the index to 3, but the playlist is sorted by "title", and the track title starts with "A" and all the other track start with the letter "Z", then the new item will end up being the first item.

Default Value: null

startPlaying boolean

If set to true, Wimpy will attempt to play the inserted item immediately.

Default Value: null



Return Value



See Also



Example 1

Assume we're creating a player with an XML playlist (foo.xml) that has 10 items in it:

// Establish a player, with an XML playlist, and disable sorting.
var myPlayer = new wimpyPlayer({media:"foo1.mp3|foo2.mp3|foo3.mp3", sort:"none"}); </script>

<p><a href="javascript:append1();">Append 1</a></p>
<p><a href="javascript:append2();">Append 2</a></p>
<p><a href="javascript:append3();">Append 3</a></p>
<p><a href="javascript:append4();">Append 4</a></p>

// Add an item to the top of the list
function append1 (){
myPlayer.appendPlaylist("fooA.mp3", 1, true);
} // To place new item at bottom of list
function append2 (){ myPlayer.appendPlaylist("fooB.mp3"); } // To place a new item at bottom of list and start playing:
function append3 (){
// When we set the "atIndex" argument to null, we'll cause it to use the default value. By default, appending a playlist will always put the new stuff at the bottom of the list. myPlayer.appendPlaylist("fooC.mp3", null, true);

// To place 2 new item in the middle of list:
function append4 (){
myPlayer.appendPlaylist("fooD.mp3|fooF.mp3", 2);
} </script>


Example 2

<!-- Create a Player Instance on th page -->
<div id="player1" data-wimpyplayer></div>

<!-- Add a little space between the player and the simple link -->

<!-- Create a simple link to load the items -->
<a href="javascript:loadPlaylist()">Load Playlist Items</a>

function loadPlaylist(){
		var myPlayer = wimpy.getPlayer("player1");

// Disable sorting, otherwise, the items won't go where you think!
// Append with a pipe delimited string: myPlayer.appendPlaylist("track1.mp3|track2.mp3"); // Append with raw Javascript
var myNewList = [ { title : "Track 3", file : "track3.mp3", image : "cover3.jpg" }, { title : "Track 4", file : "track4.mp3", image : "cover4.jpg" } ];
myPlayer.appendPlaylist(myNewList); // Append with raw JSON string: var myNewList = '[{"file":"track5.mp3","image":"cover5.jpg"}, {"file":"track6.mp3","image":"cover6.jpg"}]'; myPlayer.appendPlaylist(myNewList); // Append as the 3rd item using the "atIndex" parameter
myPlayer.appendPlaylist("Should_Be_Third.mp3", 3); // NOTE: Wimpy automatically replaces "_" underscores with a regualr space character! } </script>