Functions for managing foobar2000 playlists.
Members
-
static ActivePlaylist :number
-
-1 if there is no active playlist.
Examples
console.log(plman.ActivePlaylist);plman.ActivePlaylist = 1; // Switches to 2nd playlist. -
static PlaybackOrder :number
-
0 - Default
1 - Repeat (Playlist)
2 - Repeat (Track)
3 - Random
4 - Shuffle (tracks)
5 - Shuffle (albums)
6 - Shuffle (folders) -
static PlayingPlaylist :number
-
-1 if there is no playing playlist.
Example
console.log(plman.PlayingPlaylist); -
static, readonly PlaylistCount :number
-
-
static, readonly PlaylistRecycler :FbPlaylistRecycler
-
A Recycle Bin for playlists.
Methods
-
static AddItemToPlaybackQueue(handle)
-
Parameters:
Name Type Description handleFbMetadbHandle -
static AddLocations(playlistIndex, paths, selectopt)
-
This operation is asynchronous and may take some time to complete if it's a large array.
Parameters:
Name Type Attributes Default Description playlistIndexnumber pathsArray.<string> An array of files/URLs selectboolean <optional>
false 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. Example
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. -
static AddPlaylistItemToPlaybackQueue(playlistIndex, playlistItemIndex)
-
Parameters:
Name Type Description playlistIndexnumber playlistItemIndexnumber -
static ClearPlaylist(playlistIndex)
-
Parameters:
Name Type Description playlistIndexnumber Example
plman.ClearPlaylist(plman.PlayingPlaylist); -
static ClearPlaylistSelection(playlistIndex)
-
Parameters:
Name Type Description playlistIndexnumber Example
plman.ClearPlaylistSelection(plman.ActivePlaylist); -
static CreateAutoPlaylist(playlistIndex, name, query, sortopt, flagsopt) → {number}
-
Parameters:
Name Type Attributes Default Description playlistIndexnumber namestring Name for the new autoplaylist. querystring Title formatting pattern for forming the playlist content. sortstring <optional>
'' Title formatting pattern for sorting. flagsnumber <optional>
0 1 - when set, will keep the autoplaylist sorted and prevent user from reordering it. Returns:
number - Index of the created playlist. -
static CreatePlaylist(playlistIndex, name) → {number}
-
Parameters:
Name Type Description playlistIndexnumber namestring Returns:
number - Index of the created playlist.Examples
// 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'); -
static DuplicatePlaylist(playlistIndex, nameopt, nullable) → {number}
-
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).Parameters:
Name Type Attributes Description playlistIndexnumber namestring <optional>
<nullable>
A name for the new playlist. If the name is "" or undefined, the name of the source playlist will be used. Returns:
number - Index of the created playlist. -
static EnsurePlaylistItemVisible(playlistIndex, playlistItemIndex)
-
Signals playlist viewers to display the track (e.g. by scrolling to it's position).
Parameters:
Name Type Description playlistIndexnumber playlistItemIndexnumber -
static ExecutePlaylistDefaultAction(playlistIndex, playlistItemIndex) → {boolean}
-
Starts playback by executing default doubleclick/enter action unless overridden by a lock to do something else.
Parameters:
Name Type Description playlistIndexnumber playlistItemIndexnumber Returns:
boolean - -1 on failure. -
static FindOrCreatePlaylist(name, unlocked) → {number}
-
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.Parameters:
Name Type Description namestring unlockedboolean 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. Returns:
number - Index of the found or created playlist. -
static FindPlaybackQueueItemIndex(handle, playlistIndex, playlistItemIndex) → {number}
-
Parameters:
Name Type Description handleFbMetadbHandle playlistIndexnumber playlistItemIndexnumber Returns:
number - Returns position in queue on success, -1 if track is not in queue. -
static FindPlaylist(name) → {number}
-
Parameters:
Name Type Description namestring Case insensitive. Returns:
number - Index of the found playlist on success, -1 on failure. -
static FlushPlaybackQueue()
-
-
static GetPlaybackQueueContents() → {Array.<FbPlaybackQueueItem>}
-
Returns:
Array.<FbPlaybackQueueItem>Example
let contents = plman.GetPlaybackQueueContents(); if (contents.length) { // access properties of first item console.log(contents[0].PlaylistIndex, contents[0].PlaylistItemIndex); } -
static GetPlaybackQueueHandles() → {FbMetadbHandleList}
-
Returns:
FbMetadbHandleListExample
let handles = plman.GetPlaybackQueueHandles(); if (handles.Count > 0) { // use "Count" to determine if Playback Queue is active. } -
static GetPlayingItemLocation() → {FbPlayingItemLocation}
-
Retrieves playlist position of currently playing item.
On failure, the property FbPlayingItemLocation#IsValid will be set to false.Returns:
FbPlayingItemLocation -
static GetPlaylistFocusItemIndex(playlistIndex) → {number}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
number - Returns -1 if nothing is selectedExample
let focus_item_index = plman.GetPlaylistFocusItemIndex(plman.ActivePlaylist); // 0 would be the first item -
static GetPlaylistItems(playlistIndex) → {FbMetadbHandleList}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
FbMetadbHandleListExample
let handle_list = plman.GetPlaylistItems(plman.PlayingPlaylist); -
static GetPlaylistLockedActions(playlistIndex) → {Array.<string>}
-
Returns the list of blocked actions
Parameters:
Name Type Description playlistIndexnumber Returns:
Array.<string> - May contain the following:
- 'AddItems'
- 'RemoveItems'
- 'ReorderItems'
- 'ReplaceItems'
- 'RenamePlaylist'
- 'RemovePlaylist'
- 'ExecuteDefaultAction' -
static GetPlaylistLockName(playlistIndex) → nullable {string}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
string - name of lock owner if there is a lock, null otherwise -
static GetPlaylistName(playlistIndex) → {string}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
stringExample
console.log(plman.GetPlaylistName(plman.ActivePlaylist)); -
static GetPlaylistSelectedItems(playlistIndex) → {FbMetadbHandleList}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
FbMetadbHandleListExample
let selected_items = plman.GetPlaylistSelectedItems(plman.ActivePlaylist); -
static InsertPlaylistItems(playlistIndex, base, handle_list, selectopt)
-
Parameters:
Name Type Attributes Default Description playlistIndexnumber basenumber Position in playlist handle_listFbMetadbHandleList Items to insert selectboolean <optional>
false If true then inserted items will be selected Examples
Add all library tracks to the beginning of playlist.
let ap = plman.ActivePlaylist; plman.InsertPlaylistItems(ap, 0, fb.GetLibraryItems());Add all library tracks to end of playlist.
let ap = plman.ActivePlaylist; plman.InsertPlaylistItems(ap, plman.PlaylistItemCount(ap), fb.GetLibraryItems()); -
static InsertPlaylistItemsFilter(playlistIndex, base, handle_list, selectopt)
-
Same as plman.InsertPlaylistItems except any duplicates contained in handle_list are removed.
Parameters:
Name Type Attributes Default Description playlistIndexnumber basenumber Position in playlist handle_listFbMetadbHandleList Items to insert selectboolean <optional>
false If true then inserted items will be selected -
static IsAutoPlaylist(playlistIndex) → {boolean}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
boolean -
static IsPlaylistItemSelected(playlistIndex, playlistItemIndex) → {boolean}
-
Parameters:
Name Type Description playlistIndexnumber playlistItemIndexnumber Returns:
boolean -
static IsPlaylistLocked(playlistIndex) → {boolean}
-
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.Parameters:
Name Type Description playlistIndexnumber Returns:
boolean- Deprecated:
- Yes
-
static IsRedoAvailable(playlistIndex) → {boolean}
-
Returns whether a redo restore point is available for specified playlist.
Related methods: plman.IsUndoAvailable, plman.Redo, plman.Undo, plman.UndoBackupParameters:
Name Type Description playlistIndexnumber Returns:
boolean -
static IsUndoAvailable(playlistIndex) → {boolean}
-
Returns whether an undo restore point is available for specified playlist.
Related methods: plman.IsRedoAvailable, plman.Redo, plman.Undo, plman.UndoBackupParameters:
Name Type Description playlistIndexnumber Returns:
boolean -
static MovePlaylist(from, to) → {boolean}
-
Parameters:
Name Type Description fromnumber tonumber Returns:
boolean -
static MovePlaylistSelection(playlistIndex, delta) → {boolean}
-
Parameters:
Name Type Description playlistIndexnumber deltanumber Returns:
booleanExample
// Moves selected items to end of playlist. plman.MovePlaylistSelection(plman.ActivePlaylist, plman.PlaylistItemCount(plman.ActivePlaylist)); -
static PlaylistItemCount(playlistIndex) → {number}
-
Parameters:
Name Type Description playlistIndexnumber Returns:
numberExample
console.log(plman.PlaylistItemCount(plman.PlayingPlaylist)); // 12 -
static 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.UndoBackupParameters:
Name Type Description playlistIndexnumber -
static RemoveItemFromPlaybackQueue(index)
-
Parameters:
Name Type Description indexnumber -
static RemoveItemsFromPlaybackQueue(affectedItems)
-
Parameters:
Name Type Description affectedItemsArray.<number> Array like [1, 3, 5] -
static RemovePlaylist(playlistIndex) → {boolean}
-
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.Parameters:
Name Type Description playlistIndexnumber Returns:
boolean -
static RemovePlaylistSelection(playlistIndex, cropopt)
-
Parameters:
Name Type Attributes Default Description playlistIndexnumber cropboolean <optional>
false If true, then removes items that are NOT selected. Examples
<Remove selected items from playlist> plman.RemovePlaylistSelection(plman.ActivePlaylist);<Remove items that are NOT selected> plman.RemovePlaylistSelection(plman.ActivePlaylist, true); -
static RemovePlaylistSwitch(playlistIndex) → {boolean}
-
Removes the specified playlist.
This automatically sets another playlist as active if removing the active playlist.Parameters:
Name Type Description playlistIndexnumber Returns:
boolean -
static RenamePlaylist(playlistIndex, name) → {boolean}
-
Parameters:
Name Type Description playlistIndexnumber namestring Returns:
boolean -
static 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.
Example
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 } } -
static SetPlaylistFocusItem(playlistIndex, playlistItemIndex)
-
Parameters:
Name Type Description playlistIndexnumber playlistItemIndexnumber Example
plman.SetPlaylistFocusItem(plman.ActivePlaylist, 0); -
static SetPlaylistFocusItemByHandle(playlistIndex, handle)
-
Parameters:
Name Type Description playlistIndexnumber handleFbMetadbHandle Example
let ap = plman.ActivePlaylist; let handle = plman.GetPlaylistItems(ap)[1]; // 2nd item in playlist plman.SetPlaylistFocusItemByHandle(ap, handle); -
static 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_spider_monkey_panel`. The owner of the lock can be checked via plman.GetPlaylistLockName.Parameters:
Name Type Description playlistIndexnumber lockedActionsArray.<string> May contain the following:
- 'AddItems'
- 'RemoveItems'
- 'ReorderItems'
- 'ReplaceItems'
- 'RenamePlaylist'
- 'RemovePlaylist'
- 'ExecuteDefaultAction' -
static SetPlaylistSelection(playlistIndex, affectedItems, state)
-
Parameters:
Name Type Description playlistIndexnumber affectedItemsArray.<number> An array of item indexes. stateboolean Example
// Selects first, third and fifth tracks in playlist. This does not affect other selected items. plman.SetPlaylistSelection(plman.ActivePlaylist, [0, 2, 4], true); -
static SetPlaylistSelectionSingle(playlistIndex, playlistItemIndex, state)
-
Parameters:
Name Type Description playlistIndexnumber playlistItemIndexnumber stateboolean Examples
// 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); -
static ShowAutoPlaylistUI(playlistIndex) → {boolean}
-
Shows popup window letting you edit certain autoplaylist properties.
Before using, check if your playlist is an autoplaylist by using plman.IsAutoPlaylist;Parameters:
Name Type Description playlistIndexnumber Returns:
booleanExample
fb.ShowAutoPlaylistUI(plman.ActivePlaylist); -
static SortByFormat(playlistIndex, pattern, selected_items_onlyopt) → {boolean}
-
Parameters:
Name Type Attributes Default Description playlistIndexnumber Index of playlist to alter. patternstring Title formatting pattern to sort by. Set to "" to randomise the order of items. selected_items_onlyboolean <optional>
false Returns:
boolean - true on success, false on failure (playlist locked etc). -
static SortByFormatV2(playlistIndex, pattern, directionopt) → {boolean}
-
Parameters:
Name Type Attributes Default Description playlistIndexnumber Index of playlist to alter. patternstring Title formatting pattern to sort by. directionnumber <optional>
1 1 - ascending
-1 - descendingReturns:
boolean -
static SortPlaylistsByName(directionopt)
-
Parameters:
Name Type Attributes Default Description directionnumber <optional>
1 1 - ascending
-1 - descending -
static 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.UndoBackupParameters:
Name Type Description playlistIndexnumber -
static 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.UndoParameters:
Name Type Description playlistIndexnumber