Load from bytes
You already have the bytes β from a fetch with auth headers, a <input type="file"> upload, an IndexedDB cache, or a Node.js readFile on the server. Hand the buffer to api.load() and skip the built-in fetcher entirely.
When the bytes come from youβ
Any pipeline that already has the file in memory belongs here:
- Node.js and server-side rendering β
fs.readFileSyncproduces aBuffer. - Backends that stream from S3, a database blob column, or an internal API.
- Browser code that fetched the file with a custom
fetch(auth headers, retries, progress reporting). - Desktop and mobile hosts that read from the local filesystem or a content provider.
api.load() accepts a Uint8Array or an ArrayBuffer on every runtime. alphaTab probes the leading bytes to pick an importer β Guitar Pro, MusicXML, Capella, or alphaTex β so you do not tell it what format you handed over.
Pair it with track selectionβ
The second argument to api.load() picks which tracks render on arrival. Pass [0] to open a multi-track file on the first track only, or [0, 2, 5] to render a subset. Omitting the argument uses whatever core.tracks was set to at construction time.
Show it in codeβ
import * as alphaTab from '@coderline/alphatab';
const container = getAlphaTabContainer();
const api = new alphaTab.AlphaTabApi(container, {
// No core.file here β the bytes arrive after construction.
});
const bytes = await readScoreFile('song.gp');
api.load(bytes, [0]);
api.scoreLoaded.on((score) => {
console.log(`Loaded ${score.title}, ${score.tracks.length} tracks total`);
});
getAlphaTabContainer() is a placeholder for the platform-specific step of obtaining the render target. readScoreFile() is a placeholder for the platform-specific step of producing a Uint8Array β fs.promises.readFile on Node.js, System.IO.File.ReadAllBytes on .NET, ContentResolver.openInputStream on Android, or fetch(...).then(r => r.arrayBuffer()) in the browser.
Where to look nextβ
- Load from a URL β the browser-only path when alphaTab does the fetch.
- Direct importer use β build a
Scorefrom bytes without instantiating an API. - Reacting to a loaded score β the
scoreLoadedevent. - Selecting and switching tracks β the second argument to
api.load(). api.loadandcore.tracksin the reference.