AudioTrack (Android)
The in-browser demo below uses Web Audio because these docs live in a browser. The code snippet on this page applies on the Android runtime.
Understanding which backend runs where matters when you cross-compile a shared alphaTab integration to another runtime. On Android, alphaTab's synth pipeline ends at AndroidSynthOutput โ an ISynthOutput implementation that pushes 44.1 kHz stereo float samples to an android.media.AudioTrack through a background worker thread.
What runs on the audio threadโ
AndroidSynthOutput sits on top of a CircularSampleBuffer sized from player.bufferTimeInMilliseconds. A companion AndroidAudioWorker owns the AudioTrack, pulls samples via read in 4096-sample chunks, and writes them to the track. Every read triggers samplesPlayed, which drives the position cursor and midiEventsPlayed.
Nothing about the backend needs configuration inside your app code. The AlphaTabView widget wires it up automatically when the player is enabled.
Selecting an output deviceโ
AlphaTabApi.enumerateOutputDevices queries AudioManager.GET_DEVICES_OUTPUTS and returns every sink device. Each device exposes the Android id as deviceId and productName as label. setOutputDevice forwards to the underlying AudioTrack.setPreferredDevice, so switching output happens without tearing playback down.
Show it in codeโ
import alphaTab.AlphaTabApi
import alphaTab.synth.ISynthOutputDevice
val api: AlphaTabApi = getAlphaTabApi() // your AlphaTabView-hosted instance
api.playerReady.on {
lifecycleScope.launch {
val devices = api.enumerateOutputDevices()
devices.forEach { device ->
Log.d("alphaTab", "${device.label} (id=${device.deviceId})")
}
// Route to a specific device; pass null to fall back to the system default.
val preferred = devices.firstOrNull { it.label.contains("Bluetooth") }
api.setOutputDevice(preferred)
}
}
getAlphaTabApi() is a placeholder for the platform-specific step of obtaining the API instance โ on Android you get one from the AlphaTabView you embedded in your layout.
Where to look nextโ
- Audio buffer size โ how
bufferTimeInMillisecondsmaps onto the AudioTrack buffer count on Android. - Selecting an output device (Web) โ the same shape of API on the browser side.
- Web Audio and AudioWorklet and NAudio (.NET) โ the sibling backends on the other runtimes.
api.enumerateOutputDevicesandapi.setOutputDeviceโ the routing API in the reference.AlphaTabViewon Android โ how the backend gets instantiated.