Repository navigation
API
dxcufgb edited this page Oct 30, 2026
·
1 revision
For macro and module authors.
const sst = game.modules.get("dxcufgbs-scenario-soundtrack").api;
sst.playScenario("Combat"); // by id or name, e.g. a custom theme "Feywild"
sst.playScenario("tavern", { listId: "…" }); // a specific playlist bound to that scenario
sst.playList("Spooky ambience"); // one playlist, by id or name
sst.pause(); sst.resume(); sst.togglePause();
sst.skipTrack(); sst.nextList(); sst.stop();
sst.playSceneScenario(canvas.scene); // play the scenario bound to a scene, unless it is already playing
sst.getState(); // what is playing: { scenarioId, listId, paused, … }
sst.getLibrary(); // a copy of { folders, lists, scenarios, automation }
sst.openPanel();
sst.bindScene(); // ask which scenario belongs to a scene (default: the current one)
sst.exportSetup(); // download the whole setup as a file
await sst.importSetup(json, { mode: "merge", scenes: true }); // or mode: "replace"Only the GM can change the music. Every client hears what the GM starts.
- For players, the playback calls (
playScenario,playList,pause,resume,togglePause,skipTrack,nextList,stop,playSceneScenario) are refused with the warning "Only the GM can control the soundtrack.". -
openPanelshows the same warning, andbindScenedoes nothing.
- The playback calls are async; all but
playSceneScenarioresolve totruewhen the music changed, orfalsewhen nothing happened (unknown name, no playlists bound, nothing playing, not the GM). - GM:
importSetuptakes the export as an object or JSON text, throws when it isn't a Scenario Soundtracks export, and resolves to the counts of what was added ({ folders, lists, scenarios, bindings, scenes }). -
exportSetupalso returns the exported data.
The API is set in the ready hook, so use it from ready on and check that it is there:
Hooks.once("ready", () => {
const sst = game.modules.get("dxcufgbs-scenario-soundtrack")?.api;
if (!sst) return; // Scenario Soundtracks not installed or not enabled
// …
});Add { "id": "dxcufgbs-scenario-soundtrack", "type": "module" } to relationships.recommends in your module.json.
A scene's soundtrack is the scene flag scenario (scene.getFlag("dxcufgbs-scenario-soundtrack", "scenario")):
- a scenario id,
-
""for No soundtrack, - or
undefinedwhen nobody has decided yet.
To react to the music changing, listen to dxcufgbs-scenario-soundtrack.changed.
- It is called with
Hooks.callAll(name, state, previous)on every client (GM and players) each time the GM changes what is playing: a new scenario or playlist, pause, resume, skip or stop. -
stateandpreviousare plain copies of the new and the old state, in the shapegetState()returns ({ scenarioId, listId, paused, skip, … };listIdisnullwhen the music stopped). -
previousis the state this client saw before the change. - An error in your listener doesn't stop the music.
Hooks.on("dxcufgbs-scenario-soundtrack.changed", (state, previous) => {
if (state.listId && !previous.listId) console.log("music started", state.scenarioId);
if (!state.listId) console.log("music stopped");
});Dxcufgb's Workshop: every Foundry VTT project, video and changelog in one place · Support on Ko-fi · MIT License
Using it
- Installation
- Getting Started
- Playlists
- Scenarios and Themes
- Playing for the Table
- Scene Soundtracks
- Combat Automation
- Import and Export
- Settings
Music services
For module authors
Help