isAudioDecoderSupported static method
Returns true if an AudioDecoder can actually be configured for
codecString at sampleRate/channels.
hasAudioDecoder only proves the CONSTRUCTOR exists; a browser can ship the API without a given codec. Checking here lets the WebCodecs backend decline cleanly so the negotiator falls through to a fallback, instead of configuring and throwing at the user.
Returns false if hasAudioDecoder is false or on any error.
Implementation
static Future<bool> isAudioDecoderSupported(
String codecString, {
int sampleRate = 48000,
int channels = 2,
}) async {
if (!hasAudioDecoder) return false;
try {
final support = await wc.AudioDecoder.isConfigSupported(
wc.AudioDecoderConfig(
codec: codecString,
sampleRate: sampleRate,
numberOfChannels: channels,
),
).toDart;
return support.supported;
} catch (_) {
// Older implementations lack isConfigSupported entirely. Absence of the
// probe is not evidence of absence of the codec — assume supported and
// let configure() be the judge, exactly as before this check existed.
return true;
}
}