createAudioDecoder method
Future<PlatformAudioDecoder?>
createAudioDecoder(
- AudioDecoderConfig config, {
- BackendContext? context,
override
Construct an audio decoder. Default implementation returns null —
backends without audio support don't need to override.
Implementation
@override
Future<PlatformAudioDecoder?> createAudioDecoder(
AudioDecoderConfig config, {
BackendContext? context,
}) async {
if (!_audioCodecs.contains(config.codec)) return null;
if (!WebCapability.hasAudioDecoder) return null;
// The constructor existing does not mean this codec is implemented. Ask
// before committing, so an unsupported codec falls through to a lower
// -priority backend (e.g. the decodeAudioData fallback) instead of
// configuring and throwing in the caller's face.
if (!await WebCapability.isAudioDecoderSupported(
audioCodecString(config.codec, config.backendOptions),
sampleRate: config.sampleRate ?? 48000,
channels: config.channels ?? 2,
)) {
return null;
}
return await WorkerAudioDecoder.tryCreate(config) ??
await WebCodecsAudioDecoder.create(config);
}