addAudioRenderer method
- required AudioFrameCallback onFrame,
- AudioRendererOptions options = const AudioRendererOptions(),
Register a callback to receive raw PCM audio frames from this track.
Multiple renderers with different options each get their own capture
pipeline. Renderers sharing the same options share a single capture.
Returns a function that, when called, removes this renderer. When the last renderer for a given options config is removed, that capture stops automatically.
Implementation
CancelListenFunc addAudioRenderer({
required AudioFrameCallback onFrame,
AudioRendererOptions options = const AudioRendererOptions(),
}) {
final group = _captureGroups.putIfAbsent(
options,
() => _AudioCaptureGroup(track: mediaStreamTrack, options: options),
);
group.renderers.add(onFrame);
return () async {
group.renderers.remove(onFrame);
if (group.renderers.isEmpty) {
_captureGroups.remove(options);
await group.stop();
}
};
}