stageResolvedAudioToSandbox function
Future<AudioMixPlan>
stageResolvedAudioToSandbox({
- required List<
ResolvedAudioTrack> tracks, - required RenderSandbox sandbox,
- required AudioByteLoader loadBytes,
- double masterVolume = 1,
Stages every resolved audio tracks into sandbox and builds the encoder
AudioMixPlan, without touching the file system.
Each track's bytes (fetched through loadBytes) are written under the bare
name audio_<i>_<cacheKey> the encoder -is, then turned into one
AudioTrackNode via AudioTrackNode.fromResolved (so delay, trim, gain,
fade, and loop match every other backend). The cache key comes from
audioSourceFromString, so an in-browser render and a desktop render name the
same track identically and the encode args stay byte-identical. masterVolume
scales the final mix. An empty list stages nothing and returns an empty plan,
so the encoder's -an path is unchanged.
Implementation
Future<AudioMixPlan> stageResolvedAudioToSandbox({
required List<ResolvedAudioTrack> tracks,
required RenderSandbox sandbox,
required AudioByteLoader loadBytes,
double masterVolume = 1,
}) async {
final nodes = <AudioTrackNode>[];
for (var i = 0; i < tracks.length; i++) {
final track = tracks[i];
final name = 'audio_${i}_${audioSourceFromString(track.source).cacheKey}';
final bytes = await loadBytes(track.source);
await sandbox.writeBytes(name, bytes);
nodes.add(AudioTrackNode.fromResolved(track, name: name));
}
return buildAudioMixPlan(nodes, masterVolume: masterVolume);
}