Documentation/Callbacks
module

Callbacks

Callbacks.js:1
function

on_always_on_top_changed

Callbacks.js:11
on_always_on_top_changed(state)

Called when "Always On Top" state changes: from using the menu, Alt + A, fb.AlwaysOnTop and etc.

Parameters

NameTypeDescription
stateboolean
function

on_button_click

Callbacks.js:606
on_button_click(id)

Parameters

NameTypeDescription
idnumber

of button created with window.CreateButton and accessed by ButtonObject.ID property.

function

on_char

Callbacks.js:19
on_char(code)

Note: in order to use this callback, use window.DlgCode(DLGC_WANTCHARS).
See DLGC_WANTCHARS

Parameters

NameTypeDescription
codenumber

UTF16 encoded char

function

on_colours_changed

Callbacks.js:28
on_colours_changed()

Called when colours are changed via default UI/columns UI preferences.
Note: use window.GetColourCUI / window.GetColourDUI to get new colours.

function

on_console_refresh

Callbacks.js:36
on_console_refresh()

Called when new records are appended to foobar2000 console log.
Note: Can used with console.GetLines or console.ClearBacklog
CAUTION: Don't call console.log in this callback

function

on_cursor_follow_playback_changed

Callbacks.js:45
on_cursor_follow_playback_changed(state)

Called when "cursor follow playback" state is changed.

Parameters

NameTypeDescription
stateboolean

current "cursor follow playback" value

function

on_download_file_done

Callbacks.js:639
on_download_file_done(path, success, error_text)

Called when utils.DownloadFileAsync thread is finished

Parameters

NameTypeDescription
pathstring

of downloaded file

successboolean
error_textstring
function

on_drag_drop

Callbacks.js:53
on_drag_drop(action, x, y, mask)

See fb.DoDragDrop documentation and

Parameters

NameTypeDescription
actionDropTargetAction
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON

Example source

function

on_drag_enter

Callbacks.js:65
on_drag_enter(action, x, y, mask)

See fb.DoDragDrop documentation and

Parameters

NameTypeDescription
actionDropTargetAction
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON

Example source

function

on_drag_leave

Callbacks.js:77
on_drag_leave()

See fb.DoDragDrop documentation and

Example source

function

on_drag_over

Callbacks.js:85
on_drag_over(action, x, y, mask)

See fb.DoDragDrop documentation and

Parameters

NameTypeDescription
actionDropTargetAction
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON

Example source

function

on_dsp_preset_changed

Callbacks.js:97
on_dsp_preset_changed()

Called when DSP preset changes.
Note: this callback is only available in foobar2000 v1.4 and later.
Note2: does not get called when presets are added or removed.

function

on_focus

Callbacks.js:106
on_focus(is_focused)

Called when the panel gets or loses focus.

Parameters

NameTypeDescription
is_focusedboolean

New focus state

function

on_font_changed

Callbacks.js:114
on_font_changed()

Called when fonts are changed via DUI or CUI preferences. Note: you can retrieve fonts using window.GetFontDUI / window.GetFontCUI.

function

on_get_album_art_done

Callbacks.js:122
on_get_album_art_done(handle, art_id, image, image_path)

Called when thread created by utils.GetAlbumArtAsync or utils.GetAlbumArtAsyncV2 is done.

Parameters

NameTypeDescription
handleFbMetadbHandle
art_idnumber

See AlbumArtId flags

image?GdiBitmap

(or D2DBitmap if window.DrawMode == 1). Null on failure

image_pathstring

path to image file (or music file if image is embedded)

function

on_http_request_done

Callbacks.js:670
on_http_request_done(task_id, success, response_text, status, response_headers)

Called when utils.HTTPRequestAsync request is finished

Parameters

NameTypeDescription
task_idnumber

task id returned by utils.HTTPRequestAsync

successboolean
response_textstring
statusnumber

HTTP response code

response_headersstring

stringified JSON containing response headers

function

on_item_focus_change

Callbacks.js:133
on_item_focus_change(playlistIndex, from, to)

Called when focused item in playlist has been changed.

Parameters

NameTypeDescription
playlistIndexnumber
fromnumber

index of the previous focused item or -1 if there was no focused item.

tonumber

index of the new focued item

function

on_item_played

Callbacks.js:143
on_item_played(handle)

Called when at least one minute of the track has been played or the track has reached its end after at least 1/3 of it has been played through.

Parameters

NameTypeDescription
handleFbMetadbHandle
function

on_key_down

Callbacks.js:152
on_key_down(vkey)

Requires "Grab focus" enabled in the Configuration window.
In order to use arrow keys, use window.DlgCode(DLGC_WANTARROWS) (see DLGC_WANTARROWS).

Note: keyboard shortcuts defined in the main preferences are always executed first and are not passed to the callback.

Parameters

NameTypeDescription
vkeynumber

Virtual Key Code (for example VK_LEFT), refer to http://msdn.microsoft.com/en-us/library/ms927178.aspx

function

on_key_up

Callbacks.js:164
on_key_up(vkey)

Requires "Grab focus" enabled in the Configuration window.
In order to use arrow keys, use window.DlgCode(DLGC_WANTARROWS) (see DLGC_WANTARROWS).

Parameters

NameTypeDescription
vkeynumber

Virtual Key Code (for example VK_LEFT), refer to http://msdn.microsoft.com/en-us/library/ms927178.aspx

function

on_library_items_added

Callbacks.js:173
on_library_items_added(handle_list)

Parameters

NameTypeDescription
handle_listFbMetadbHandleList
function

on_library_items_changed

Callbacks.js:179
on_library_items_changed(handle_list)

Parameters

NameTypeDescription
handle_listFbMetadbHandleList
function

on_library_items_removed

Callbacks.js:185
on_library_items_removed(handle_list)

Parameters

NameTypeDescription
handle_listFbMetadbHandleList
function

on_load_image_done

Callbacks.js:191
on_load_image_done(cookie, image, image_path)

Called when thread created by gdi.LoadImageAsync is done.

Parameters

NameTypeDescription
cookienumber

the return value from the gdi.LoadImageAsync call

image?GdiBitmap

(or D2DBitmap if window.DrawMode == 1). Null on failure (invalid path/not an image)

image_pathstring

the path that was originally supplied to gdi.LoadImageAsync

function

on_locations_added

Callbacks.js:649
on_locations_added(task_id, handles)

Called when fb.AddLocationsAsync thread is finished

Parameters

NameTypeDescription
task_idnumber
handlesFbMetadbHandleList

Example

function on_mouse_lbtn_dblclk() {
    var files = ["z:\\1.mp3", "z:\\2.flac"];
    var task_id = fb.AddLocationsAsync(files);
    console.log("got task_id", task_id);
}

function on_locations_added(task_id, handle_list) {
    console.log("callback task_id", task_id);
    console.log(handle_list.Count);
}
functiondeprecated

on_main_menu

Callbacks.js:201
on_main_menu(index)
Deprecated.

On the main menu>File>Spider Monkey Panel, there are 10 menu items and whichever number is selected is sent as the "index" to this callback.
Being main menu items now means you can bind them to global keyboard shortcuts, standard toolbar buttons, panel stack splitter buttons, etc.
Remember to think carefully about where you use this code as you probably only want it to run once and so don't include it in common files and scripts where you might have multiple instances.
Important: you should avoid sharing scripts containing this code so as not to conflict with what other users may already be using.

Deprecated: use on_main_menu_dynamic instead.

Parameters

NameTypeDescription
indexnumber

Example

function on_main_menu(index) {
    switch (index) {
    case 1: // triggered when File>Spider Monkey Panel>1 is run
        do_something();
        break;
    case 2: // triggered when File>Spider Monkey Panel>2 is run
        do_something_else();
        break;
    }
}
function

on_main_menu_dynamic

Callbacks.js:232
on_main_menu_dynamic(command_id)

Called when one of the commands corresponding to this panel from main menu>File>Spider Monkey Panel>Script commands is executed.

Related methods: fb.RegisterMainMenuCommand, fb.UnregisterMainMenuCommand

Parameters

NameTypeDescription
command_idnumber

Id of the associated command

function

on_metadb_changed

Callbacks.js:242
on_metadb_changed(handle_list, fromhook)

Called when metadb contents change.

Parameters

NameTypeDescription
handle_listFbMetadbHandleList

affected items

fromhookboolean

true if notification is not from tag update, but a component that provides tag-like data from a database. E.g. foo_playcount and FbMetadbHandle.RefreshStats

function

on_mouse_lbtn_dblclk

Callbacks.js:252
on_mouse_lbtn_dblclk(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-lbuttondblclk

function

on_mouse_lbtn_down

Callbacks.js:261
on_mouse_lbtn_down(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-lbuttondown

function

on_mouse_lbtn_up

Callbacks.js:270
on_mouse_lbtn_up(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-lbuttonup

function

on_mouse_leave

Callbacks.js:279
on_mouse_leave()
function

on_mouse_mbtn_dblclk

Callbacks.js:284
on_mouse_mbtn_dblclk(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-mbuttondblclk

function

on_mouse_mbtn_down

Callbacks.js:293
on_mouse_mbtn_down(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-mbuttondown

function

on_mouse_mbtn_up

Callbacks.js:302
on_mouse_mbtn_up(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-mbuttonup

function

on_mouse_move

Callbacks.js:311
on_mouse_move(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-mousemove

function

on_mouse_rbtn_dblclk

Callbacks.js:320
on_mouse_rbtn_dblclk(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-rbuttondblclk

function

on_mouse_rbtn_down

Callbacks.js:329
on_mouse_rbtn_down(x, y, mask)

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-rbuttondown

function

on_mouse_rbtn_up

Callbacks.js:338
on_mouse_rbtn_up(x, y, mask)

You must return true, if you want to suppress the default context menu.
Note: left shift + left windows key will bypass this callback and will open default context menu.

Parameters

NameTypeDescription
xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON
Refer to https://learn.microsoft.com/ru-ru/windows/win32/inputdev/wm-rbuttonup

Returns

boolean
function

on_mouse_wheel

Callbacks.js:352
on_mouse_wheel(step)

Scroll up/down

Parameters

NameTypeDescription
stepnumber

scroll direction: -1 or 1

function

on_mouse_wheel_h

Callbacks.js:361
on_mouse_wheel_h(step)

Scroll left/right

Parameters

NameTypeDescription
stepnumber

scroll direction: -1 or 1

function

on_notify_data

Callbacks.js:369
on_notify_data(name, info)

Called in other panels after window.NotifyOthers is executed.

!!! Beware !!!
1. Data from info argument is only accessible inside on_notify_data callback: if stored and accessed outside of the callback it will throw JS error.
This also applies to the data produced from that info: e.g. storing info.Path directly (if info is FbMetadbHandle).
2. If you want to store the data from info you have to perform a deep copy:
- String(info) for strings.
- JSON.parse(JSON.stringify(info)) for serializable objects.
- new ObjectType(info) for objects that have an approppriate constructor available, e.g. new GdiBitmap(info) or new FbMetadbHandleList(info).
3. info argument is shared between panels, so it should NOT be modified in any way.

Parameters

NameTypeDescription
namestring
info*
function

on_output_device_changed

Callbacks.js:388
on_output_device_changed()

Called when output device changes. Use fb.GetOutputDevices to retrieve settings.
Note: available only in foobar2000 v1.4 and later.

function

on_paint

Callbacks.js:396
on_paint(gr)

Called when window is ready to draw.

Parameters

NameTypeDescription
grGdiGraphics
function

on_panel_mouse_enter

Callbacks.js:612
on_panel_mouse_enter(name)

Raises when mouse pointer entering JSplitter child panel area
Works only if window.TrackMouseEnterLeaveOnPanels is true

Parameters

NameTypeDescription
namestring

of panel mouse pointer enters

function

on_panel_mouse_leave

Callbacks.js:631
on_panel_mouse_leave(name)

Raises when mouse pointer leaving JSplitter child panel area
Works only if window.TrackMouseEnterLeaveOnPanels is true

Parameters

NameTypeDescription
namestring

of panel mouse pointer leaves

function

on_panel_mouse_move

Callbacks.js:620
on_panel_mouse_move(name, x, y, mask)

Raises when mouse pointer moving over JSplitter child panel area
Works only if window.TrackMouseMoveOnPanels is true

Parameters

NameTypeDescription
namestring

of panel mouse pointer moves over

xnumber
ynumber
masknumber

Mask for mouse callbacks, see flags like MK_LBUTTON

function

on_playback_dynamic_info

Callbacks.js:412
on_playback_dynamic_info()

Called when dynamic info (VBR bitrate etc) changes.

function

on_playback_dynamic_info_track

Callbacks.js:419
on_playback_dynamic_info_track()

Called when Per-track dynamic info (stream track titles etc) changes.
Happens less often than on_playback_dynamic_info.

function

on_playback_edited

Callbacks.js:427
on_playback_edited(handle)

Called when currently playing file gets edited.
It's also called by components that provide tag-like data such as foo_playcount.

Parameters

NameTypeDescription
handleFbMetadbHandle
function

on_playback_follow_cursor_changed

Callbacks.js:404
on_playback_follow_cursor_changed(state)

Called when "playback follow cursor" state is changed.

Parameters

NameTypeDescription
stateboolean

current "playback follow cursor" value

function

on_playback_new_track

Callbacks.js:436
on_playback_new_track(handle)

Playback advanced to the new track.

Parameters

NameTypeDescription
handleFbMetadbHandle
function

on_playback_order_changed

Callbacks.js:444
on_playback_order_changed(new_order_index)

Called when playback order is changed.

Parameters

NameTypeDescription
new_order_indexany

see PlaybackOrder enum

function

on_playback_pauseQueueChangeType

Callbacks.js:452
on_playback_pauseQueueChangeType(state)

Parameters

NameTypeDescription
stateboolean

true when paused, false when unpaused.

function

on_playback_queue_changed

Callbacks.js:458
on_playback_queue_changed(origin)

Parameters

NameTypeDescription
originnumber

see QueueChangeOrigin enum

function

on_playback_seek

Callbacks.js:464
on_playback_seek(time)

Parameters

NameTypeDescription
timefloat

new position in seconds

function

on_playback_starting

Callbacks.js:470
on_playback_starting(cmd, is_paused)

Playback process is being initialized.
on_playback_new_track should be called soon after this when first file is successfully opened for decoding.

Parameters

NameTypeDescription
cmdnumber

see PlaybackStartCmd enum
- 0 Default
- 1 Play
- 2 Plays the next track from the current playlist according to the current playback order
- 3 Plays the previous track from the current playlist according to the current playback order
- 4 settrack (internal fb2k value)
- 5 Plays a random track from the current playlist
- 6 resume (internal fb2k value)

is_pausedboolean

Current paused state

function

on_playback_stop

Callbacks.js:488
on_playback_stop(reason)

Parameters

NameTypeDescription
reasonnumber

see PlaybackStopReason enum

function

on_playback_time

Callbacks.js:494
on_playback_time(time)

Called every second, for time display.

Parameters

NameTypeDescription
timefloat

current playback time in seconds

function

on_playlist_item_ensure_visible

Callbacks.js:502
on_playlist_item_ensure_visible(playlistIndex, playlistItemIndex)

Parameters

NameTypeDescription
playlistIndexnumber
playlistItemIndexnumber
function

on_playlist_items_added

Callbacks.js:509
on_playlist_items_added(playlistIndex)

Parameters

NameTypeDescription
playlistIndexnumber
function

on_playlist_items_removed

Callbacks.js:515
on_playlist_items_removed(playlistIndex, new_count)

Parameters

NameTypeDescription
playlistIndexnumber
new_countnumber
function

on_playlist_items_reordered

Callbacks.js:522
on_playlist_items_reordered(playlistIndex)

Changes selection too. Doesn't actually change the set of items that are selected or item having focus, just changes their order.

Parameters

NameTypeDescription
playlistIndexnumber
function

on_playlist_items_selection_change

Callbacks.js:530
on_playlist_items_selection_change()

Workaround for some 3rd party playlist viewers not working with on_selection_changed.

function

on_playlist_stop_after_current_changed

Callbacks.js:537
on_playlist_stop_after_current_changed(state)

Called when "stop after current" is enabled/disabled.

Parameters

NameTypeDescription
stateboolean

"stop after current" value

function

on_playlist_switch

Callbacks.js:545
on_playlist_switch()
function

on_playlists_changed

Callbacks.js:550
on_playlists_changed()

Called when:
- Playlists are added/removed/reordered/renamed.
- A playlist's lock status changes through the use of plman.SetPlaylistLockedActions or components such as foo_utils or foo_playlist_attributes.

function

on_replaygain_mode_changed

Callbacks.js:560
on_replaygain_mode_changed(new_mode)

Note: available only in foobar2000 v1.4 and later.

Parameters

NameTypeDescription
new_modenumber

see ReplayGainMode enum

function

on_script_unload

Callbacks.js:568
on_script_unload()

Called when:
- Panel script is reloaded via context menu > Reload.
- Panel script is changed via panel menu > Configure.
- fb2k is exiting normally.
Not called when:
- Script fails with error.
- fb2k closed externally (e.g. killed with process manager).
- fb2k fails with exception.

function

on_selection_changed

Callbacks.js:582
on_selection_changed()

Called when selection changes based on "File>Preferences>Display>Selection viewers".

function

on_size

Callbacks.js:589
on_size(width, height)

Called when panel is resized.
Note: width and height arguments have the same values as window.Width and window.Height.
IMPORTANT: do NOT call window.Repaint from this callback!

Parameters

NameTypeDescription
widthnumber
heightnumber
function

on_volume_change

Callbacks.js:600
on_volume_change(val)

Parameters

NameTypeDescription
valfloat

volume level in dB. Minimum is -100. Maximum is 0.

function

PerformanceObserverCallback

Callbacks.js:682
PerformanceObserverCallback(entries, observer)

Callback that will be invoked when observed performance events are recorded. Specified in PerformanceObserver constructor

Parameters

NameTypeDescription
entriesPerformanceObserverEntryList

The list of performance observer entries.

observerPerformanceObserver

The observer object that is receiving the above entries.