Load MusicXML from nameless JavaScript Blob-URL #555
-
Hi@all, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi there. So instead of making a blob, you could serialize your XML document to a string, and then to an function loadMusicXml(xmlDocument) {
const xmlString = new XMLSerializer().serializeToString(xmlDocument.documentElement);
const raw = new TextEncoder().encode(xmlString); // gives you an Uint8Array with the UTF8 encoded text inside
api.load(raw, [0]);
} In general alphaTab does not care about file names, it takes the raw file data and attempts to parse it with the available importers. Every importer has some basic mechanism to detect whether it should attempt reading the rest of the data fully. So basically it's a trial and error where the first importer that works wins. |
Beta Was this translation helpful? Give feedback.
Hi there.
Is there a particular reason why you create a blob? In theory alphaTab can load directly from
ArrayBuffer
orUint8Array
. Thestring
loading variant is more meant for remote resources that need to be loaded via AJAX. I haven't tried what happens when you trigger an XmlHttpRequest to a blob url but I guess it will fail.So instead of making a blob, you could serialize your XML document to a string, and then to an
Uint8Array
. Maybe something like the following could work out for you (untested):