removePlaylistItems

 

Removing playlist items is a little tricky because there can be any number of ways to identify a particular item to delete.

For example, some folks may want to simply say "remove the first item". While others may want to remove all of the items that match a specific criteria.

Hence, this function is set up to extend support to these different approaches.

For advanced users, this function may not provide as much functionality as needed. In which case, you can always leverage the getPlaylist + setPlaylist. Where you can retrive the current playlist from the player, then loop through the results and weed out what you don't want, then re assert the playlist using setPlaylist. (This is actually kind of how the internal mechanisms of this function work.)

This function attempts to restore the playlist to its original state (sans the items deleted). Meaning that if a track is currently playing while the operation is executed, using the next or previous button will maintain continuity. Likewise, if the user has the playlist scrolled, the this function attempts to re-scroll the playlist back to the original position.

 

removePlaylistItems(field, value)

 

Parameters

field string

The name of the field to check against. The field name can be any field supplied within the Track Dataset -- including any of the "Special Fields"  or custom fields you've included.

By default, the simplest playlist will contain at the very least the file, title and the Special Fields.

 

value mixed

Playlist items that match this value will be deleted. Every item in the playlist will be checked against this value (or set of values when an array is used) to determine if the item should be removed.

"Value" may be singular or an array. Using an array allows you to provide multiple values to check.

For example if you want to delete item #3, 1, 6, then you can define an array as:

removePlaylistItems("i", [3,1,6]);

 

 

 

Return Value

removed items array

Returns an array containing all the items that were deleted.

 

 

See Also

 

Examples

Example 1

<!-- Create a player instance and set the "id" to "myPlayerAsDiv" so we can reference it in our javascript -->
<div id="myPlayer" data-wimpyplayer data-media="song1.mp3|song2.mp3|song3.mp3"></div>

<!-- Remove with on line of javascript -->
<p><input type="button" onclick='javascript:wimpy.getPlayer("myPlayer").removePlaylistItems("i", 1)' value="Remove The second Item" /></p>

 

Example 2

<script>
var simpleList = "song1.mp3|song2.mp3|song3.mp3"

var myPlayer = new wimpyPlayer({
                   target: "MyTarget",           
                   media: simpleList
                 });
</script>

<!-- 
"i" is a special reference to the internal array index.
The "i" field is automatically added to each playlist item by wimpy.
Indices are zero-based (e.g. the first item is 0, the second 1)
-->
<p><input type="button" onclick='myPlayer.removePlaylistItems("i", [0,2])' value="Remove First and Last" /></p>