The question is about controlling audio by means of Settings API
From what i can see in docs there are only audio macros available and after looking at source code i found that it seems these macroses does not use any JS API for it so i assume there is none.
So question is it possible to execute macros from JS?
Of course i could copy-paste macros code from sources, but i would prefer to use up-to-date version of audio macros
For now i'm going to stick with following code:
var bgmHandler = function () {
var cur_track = State.variables["current_track"];
if (cur_track == null) return;
if (settings.bgm) {
Macro.get("cacheaudio")
.tracks[cur_track]
.unmute()
} else {
Macro.get("cacheaudio")
.tracks[cur_track]
.mute()
}
};
/* Config menu */
Setting.addToggle("bgm", {
label : "Music",
default : true,
onInit : bgmHandler,
onChange : bgmHandler
});
I'll appreaciate if someone can advise me of any more simple JS variants to interact with audio API
Comments
The <<cacheaudio>> macro does the initial setup of each piece of audio, then wraps it within an instance of AudioWrapper. From there, the <<audio>> macro really just uses the wrapper to control playback.
The playlist is slightly different in that it clones the tracks entered into it, so that they may be controlled separately from the originals used by <<audio>>.
Yes. There are a couple of ways to do so.
By instantiating the Wikifier:
By using Wikifier.wikifyEval():
The difference between the two examples shown here is that the former eats errors, while the latter throws an exception upon encountering an error.
That doesn't mute new non-playlist audio playback, which will likely confuse the player (who probably expected the setting to silence all audio or, at least, all BGMs). It also doesn't affect the playlist, if you ever plan to use that.
If you wanted to mute all non-playlist audio, you could do it like so:
If you wanted the setting to only mute BGM, while still allowing you to play other audio here and there, then you'd probably be better off by registering your BGM into the playlist and muting that instead. For example:
I also wasn't planning to use more than just BGM and variable holds currently active track. Since it is set only via widget i thought it would be ok to do mute only on this current track
Yes, i understand that
The way i'm planning to do it is when track is going to be changed the previous one will be stopped completely
Though i'll think about using playlist later on when there will be a lot of BGMs