plman
Functions for managing foobar2000 playlists.
Functions for managing foobar2000 playlists.
ActivePlaylist: number
-1 if there is no active playlist.
console.log(plman.ActivePlaylist);plman.ActivePlaylist = 1; // Switches to 2nd playlist.
PlaybackOrder: number
See PlaybackOrder enum 0 - Default
1 - Repeat (Playlist)
2 - Repeat (Track)
3 - Random
4 - Shuffle (tracks)
5 - Shuffle (albums)
6 - Shuffle (folders)
PlayingPlaylist: number
-1 if there is no playing playlist.
console.log(plman.PlayingPlaylist);
PlaylistCount: number
PlaylistRecycler: FbPlaylistRecycler
A Recycle Bin for playlists.
AddItemToPlaybackQueue(handle)
| Name | Type | Description |
|---|---|---|
handle | FbMetadbHandle |
AddLocations(playlistIndex, paths, select)
This operation is asynchronous and may take some time to complete if it's a large array.
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
paths | Array<string> | An array of files/URLs |
select = falseoptional | boolean | If true, the active playlist will be set to the playlistIndex, the items will be selected and focus will be set to the first new item. |
plman.AddLocations(plman.ActivePlaylist, ["e:\\1.mp3"]);
// This operation is asynchronous, so any code in your script directly
// after this line will run immediately without waiting for the job to finish.
AddPlaylistItemToPlaybackQueue(playlistIndex, playlistItemIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number |
ClearPlaylist(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
plman.ClearPlaylist(plman.PlayingPlaylist);
ClearPlaylistSelection(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
plman.ClearPlaylistSelection(plman.ActivePlaylist);
CreateAutoPlaylist(playlistIndex, name, query, sort, flags)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
name | string | Name for the new autoplaylist. |
query | string | Title formatting pattern for forming the playlist content. |
sort = ''optional | string | Title formatting pattern for sorting. |
flags = 0optional | number | 1 - when set, will keep the autoplaylist sorted and prevent user from reordering it. |
number — Index of the created playlist.
CreatePlaylist(playlistIndex, name)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
name | string |
number — Index of the created playlist.
// Creates a new playlist named "New playlist", which is put at the beginning of the current playlists.
plman.CreatePlaylist(0, '');// Create a new playlist named "my favourites", which is put at the end.
plman.CreatePlaylist(plman.PlaylistCount, 'my favourites');
DuplicatePlaylist(playlistIndex, name)
Note: the duplicated playlist gets inserted directly after the source playlistIndex.
It only duplicates playlist content, not the properties of the playlist (e.g. Autoplaylist).
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
nameoptional | ?string | A name for the new playlist. If the name is "" or undefined, the name of the source playlist will be used. |
number — Index of the created playlist.
EnsurePlaylistItemVisible(playlistIndex, playlistItemIndex)
Signals playlist viewers to display the track (e.g. by scrolling to it's position).
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number |
ExecutePlaylistDefaultAction(playlistIndex, playlistItemIndex)
Starts playback by executing default doubleclick/enter action unless overridden by a lock to do something else.
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number |
boolean — -1 on failure.
FindByGUID(guid)
| Name | Type | Description |
|---|---|---|
guid | string | String representing GUID. |
number — Index of the found playlist on success, -1 on failure.
FindOrCreatePlaylist(name, unlocked)
Returns playlist index of the named playlist or creates a new one, if not found.
If a new playlist is created, the playlist index of that will be returned.
| Name | Type | Description |
|---|---|---|
name | string | |
unlocked | boolean | If true, locked playlists are ignored when looking for existing playlists. If false, the playlistIndex of any playlist with the matching name will be returned. |
number — Index of the found or created playlist.
FindPlaybackQueueItemIndex(handle, playlistIndex, playlistItemIndex)
| Name | Type | Description |
|---|---|---|
handle | FbMetadbHandle | |
playlistIndex | number | |
playlistItemIndex | number |
number — Returns position in queue on success, -1 if track is not in queue.
FindPlaylist(name)
| Name | Type | Description |
|---|---|---|
name | string | Case insensitive. |
number — Index of the found playlist on success, -1 on failure.
FlushPlaybackQueue()
GetGUID(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
stringconsole.log(plman.GetGUID(plman.ActivePlaylist));
GetPlaybackQueueContents()
Array<FbPlaybackQueueItem>let contents = plman.GetPlaybackQueueContents();
if (contents.length) {
// access properties of first item
console.log(contents[0].PlaylistIndex, contents[0].PlaylistItemIndex);
}
GetPlaybackQueueHandles()
let handles = plman.GetPlaybackQueueHandles();
if (handles.Count > 0) {
// use "Count" to determine if Playback Queue is active.
}
GetPlayingItemLocation()
Retrieves playlist position of currently playing item.
On failure, the property FbPlayingItemLocation.IsValid will be set to false.
GetPlaylistFocusItemIndex(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
number — Returns -1 if nothing is selected
let focus_item_index = plman.GetPlaylistFocusItemIndex(plman.ActivePlaylist); // 0 would be the first item
GetPlaylistItems(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
let handle_list = plman.GetPlaylistItems(plman.PlayingPlaylist);
GetPlaylistLockedActions(playlistIndex)
Returns the list of blocked actions
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
Array<string> — May contain the following:
- 'AddItems'
- 'RemoveItems'
- 'ReorderItems'
- 'ReplaceItems'
- 'RenamePlaylist'
- 'RemovePlaylist'
- 'ExecuteDefaultAction'
GetPlaylistLockName(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
?string — name of lock owner if there is a lock, null otherwise
GetPlaylistName(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
stringconsole.log(plman.GetPlaylistName(plman.ActivePlaylist));
GetPlaylistSelectedIndexes(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
Array<number>let selected_indexes = plman.GetPlaylistSelectedIndexes(plman.ActivePlaylist);
GetPlaylistSelectedItems(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
let selected_items = plman.GetPlaylistSelectedItems(plman.ActivePlaylist);
InsertPlaylistItems(playlistIndex, base, handle_list, select)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
base | number | Position in playlist |
handle_list | FbMetadbHandleList | Items to insert |
select = falseoptional | boolean | If true then inserted items will be selected |
<caption>Add all library tracks to the beginning of playlist.</caption>
let ap = plman.ActivePlaylist;
plman.InsertPlaylistItems(ap, 0, fb.GetLibraryItems());<caption>Add all library tracks to end of playlist.</caption>
let ap = plman.ActivePlaylist;
plman.InsertPlaylistItems(ap, plman.PlaylistItemCount(ap), fb.GetLibraryItems());
InsertPlaylistItemsFilter(playlistIndex, base, handle_list, select)
Same as plman.InsertPlaylistItems except any duplicates contained in handle_list are removed.
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
base | number | Position in playlist |
handle_list | FbMetadbHandleList | Items to insert |
select = falseoptional | boolean | If true then inserted items will be selected |
InvertSelection(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
IsAutoPlaylist(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanIsPlaylistItemSelected(playlistIndex, playlistItemIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number |
booleanIsPlaylistLocked(playlistIndex)
Note: returns true, if the playlist is an autoplaylist. To determine if a playlist is not an autoplaylist, but locked with something like foo_utils or foo_playlist_attributes, use with conjunction of plman.IsAutoPlaylist.
Deprecated: use plman.GetPlaylistLockedActions.
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanIsRedoAvailable(playlistIndex)
Returns whether a redo restore point is available for specified playlist.
Related methods: plman.IsUndoAvailable, plman.Redo, plman.Undo, plman.UndoBackup
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanIsUndoAvailable(playlistIndex)
Returns whether an undo restore point is available for specified playlist.
Related methods: plman.IsRedoAvailable, plman.Redo, plman.Undo, plman.UndoBackup
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanMovePlaylist(from, to)
| Name | Type | Description |
|---|---|---|
from | number | |
to | number |
booleanMovePlaylistSelection(playlistIndex, delta)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
delta | number |
boolean// Moves selected items to end of playlist.
plman.MovePlaylistSelection(plman.ActivePlaylist, plman.PlaylistItemCount(plman.ActivePlaylist));
MovePlaylistSelectionV2(playlistIndex, new_pos)
Unlike plman.MovePlaylistSelection, this has full support for non-contiguous selections and all you have to do is supply the new position index.
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
new_pos | number |
PlaylistItemCount(playlistIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
numberconsole.log(plman.PlaylistItemCount(plman.PlayingPlaylist)); // 12
Redo(playlistIndex)
Reverts specified playlist to the next redo restore point and generates an undo restore point.
Note: revert operation may be not applied if the corresponding action is locked. Use plman.GetPlaylistLockedActions to check if there are any locks present.
Related methods: plman.IsRedoAvailable, plman.IsUndoAvailable, plman.Undo, plman.UndoBackup
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
RemoveItemFromPlaybackQueue(index)
| Name | Type | Description |
|---|---|---|
index | number |
RemoveItemsFromPlaybackQueue(affectedItems)
| Name | Type | Description |
|---|---|---|
affectedItems | Array<number> | Array like [1, 3, 5] |
RemovePlaylist(playlistIndex)
Removes the specified playlist.
Note: if removing the active playlist, no playlist will be active after using this. You'll need to set it manually or use plman.RemovePlaylistSwitch instead.
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanRemovePlaylistSelection(playlistIndex, crop)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
crop = falseoptional | boolean | If true, then removes items that are NOT selected. |
<Remove selected items from playlist>
plman.RemovePlaylistSelection(plman.ActivePlaylist);<Remove items that are NOT selected>
plman.RemovePlaylistSelection(plman.ActivePlaylist, true);
RemovePlaylistSwitch(playlistIndex)
Removes the specified playlist.
This automatically sets another playlist as active if removing the active playlist.
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanRenamePlaylist(playlistIndex, name)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
name | string |
booleanReorderPlaylistItems(playlistIndex, order)
Reorders all items in the specified playlist according to the supplied permutation.
The order array must contain exactly one entry for each playlist item. Each value specifies the old item index that should appear at the corresponding new position.
The array must:
- have the same length as the playlist item count
- contain only valid item indices
- contain each item index exactly once
| Name | Type | Description |
|---|---|---|
playlistIndex | number | zero-based playlist index |
order | Array<number> | permutation describing the new playlist item order |
boolean — true if the playlist was reordered successfully
Error — If playlistIndex is invalid or order is not a valid permutation
// Changes the order from [A, B, C] to [C, A, B]
const success = ReorderPlaylistItems(0, [2, 0, 1])
ReplacePlaylistItem(playlistIndex, playlistItemIndex, handle_or_handles)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number | |
handle_or_handles | FbMetadbHandle|FbMetadbHandleList |
SelectQueryItems(playlistIndex, query)
This selects playlist items in a similar manner to the foobar2000 native playlist search.
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
query | string |
Array<number> — Array of selected indexes
SetActivePlaylistContext()
Workaround so you can use the Edit menu or run fb.RunMainMenuCommand("Edit/Something...") when your panel has focus and a dedicated playlist viewer doesn't.
plman.SetActivePlaylistContext(); // once on startup
function on_focus(is_focused) {
if (is_focused) {
plman.SetActivePlaylistContext(); // When the panel gets focus but not on every click
}
}
SetPlaylistFocusItem(playlistIndex, playlistItemIndex)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number |
plman.SetPlaylistFocusItem(plman.ActivePlaylist, 0);
SetPlaylistFocusItemByHandle(playlistIndex, handle)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
handle | FbMetadbHandle |
let ap = plman.ActivePlaylist;
let handle = plman.GetPlaylistItems(ap)[1]; // 2nd item in playlist
plman.SetPlaylistFocusItemByHandle(ap, handle);
SetPlaylistLockedActions(playlistIndex, lockedActions)
Blocks requested actions.
Note: the lock can be changed only if there is no lock or if it's owned by foo_uie_jsplitter. The owner of the lock can be checked via plman.GetPlaylistLockName.
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
lockedActions | Array<string> | May contain the following: |
SetPlaylistSelection(playlistIndex, affectedItems, state)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
affectedItems | Array<number> | An array of item indexes. |
state | boolean |
// Selects first, third and fifth tracks in playlist. This does not affect other selected items.
plman.SetPlaylistSelection(plman.ActivePlaylist, [0, 2, 4], true);
SetPlaylistSelectionSingle(playlistIndex, playlistItemIndex, state)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | |
playlistItemIndex | number | |
state | boolean |
// Deselects first playlist item. Only works when it is already selected!
plman.SetPlaylistSelectionSingle(plman.ActivePlaylist, 0, false);let ap = plman.ActivePlaylist;
// Selects last item in playlist. This does not affect other selected items.
plman.SetPlaylistSelectionSingle(ap, plman.PlaylistItemCount(ap) - 1, true);
ShowAutoPlaylistUI(playlistIndex)
Shows popup window letting you edit certain autoplaylist properties.
Before using, check if your playlist is an autoplaylist by using plman.IsAutoPlaylist;
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
booleanfb.ShowAutoPlaylistUI(plman.ActivePlaylist);
ShowPlaylistLockUI(playlistIndex)
Shows popup window letting you set various locks on playlist with specified index
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
fb.ShowPlaylistLockUI(plman.ActivePlaylist);
SortByFormat(playlistIndex, pattern, selected_items_only)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | Index of playlist to alter. |
pattern | string | Title formatting pattern to sort by. Set to "" to randomise the order of items. |
selected_items_only = falseoptional | boolean |
boolean — true on success, false on failure (playlist locked etc).
SortByFormatV2(playlistIndex, pattern, direction)
| Name | Type | Description |
|---|---|---|
playlistIndex | number | Index of playlist to alter. |
pattern | string | Title formatting pattern to sort by. |
direction = 1optional | number | 1 - ascending |
booleanSortPlaylistsByName(direction)
| Name | Type | Description |
|---|---|---|
direction = 1optional | number | 1 - ascending |
Undo(playlistIndex)
Reverts specified playlist to the last undo restore point and generates a redo restore point.
Note: revert operation may be not applied if the corresponding action is locked. Use plman.GetPlaylistLockedActions to check if there are any locks present.
Related methods: plman.IsRedoAvailable, plman.IsUndoAvailable, plman.Redo, plman.UndoBackup
| Name | Type | Description |
|---|---|---|
playlistIndex | number |
UndoBackup(playlistIndex)
Creates an undo restore point for the specified playlist. This will enable Edit>Undo menu item after calling other plman methods that change playlist content.
Note: this method should be called before performing modification to the playlist.
Related methods: plman.IsRedoAvailable, plman.IsUndoAvailable, plman.Redo, plman.Undo
| Name | Type | Description |
|---|---|---|
playlistIndex | number |