Add support for playback in Electron apps #1933
Replies: 3 comments 4 replies
-
In electron you have two parts: A node.js backend and a Chromium Frontend. The Node.js backend has no support for Web Audio. For now you likely need to use alphaTab both on the "backend" and "frontend" and communicate through channels. When using The Likely you are not using alphaTab/src/platform/javascript/BrowserUiFacade.ts Lines 112 to 117 in af692f2 I am not sure if there is a built-in way into Electron to use the Frontend APIs from the Node.js backend (e.g. simply doing a There is currently also no "NodeUiFacade" which could be used to run alphaTab (e.g. in a virtual/headless space which could be manually synchronized with an external UI). |
Beta Was this translation helpful? Give feedback.
-
The core is to initiate My solution enables alphaTab to run robustly within an Obsidian (Electron) plugin by tackling two core challenges: environment detection and asset loading. Environment Emulation The key issue is that alphaTab's AlphaTabApi is designed for pure browser environments and will throw an error if it detects a Node.js-like context (process or module objects). The fix is to create a temporary "browser-like" sandbox right before initialization: Temporarily undefine Reliable Asset Loading (Fonts & SoundFont) SoundFont & Workers: Use Obsidian's API ( SMuFL Fonts (The Critical Part): To bypass alphaTab's internal font loading via @font-face URLs (which often fails), we take manual control:
In essence, this approach creates a compatible "bubble" for alphaTab to initialize in, then pre-loads and injects all its dependencies as web-native resources (Data URLs), decoupling it entirely from the problematic file system interactions. I think it may be easier to initiate |
Beta Was this translation helpful? Give feedback.
-
Here we go 🥳🎉: https://github.com/Danielku15/alphatab-obsidian Obsidian_Bauvqze4wF.mp4It seems Obsidian does not have a general built-in way of fetching files via URLs. But that's no problem because we can access the file system via Obsidian APIs and load files. Then its just a matter of creating Blob URIs for usage. Obsidian plugins are generally meant to have always 1 main file. I saw they also just load the plugin file from disk and |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, when trying to create an
AlphaSynthWebWorkerApi
instance in the renderer process of an Electron app, an error is thrown (Workers not yet supported in Node.js
).But it should be possible to run the alphaSynth APIs in an Electron app, since it's basically a Chromium browser embedded in a desktop app. So this should be as simple as updating the detection logic to include this case, and check it with something like:
(source)
FYI, my use case is making an alphaTab plugin for Obsidian. I've tried running the above snippet in the console and it seems the detection logic is working. I can also see the
Worker
andAudioContext
objects are available, so alphaSynth should work out-of-the-box once the detection logic is updated.Beta Was this translation helpful? Give feedback.
All reactions