Capítulo 735 de 988
Before attempting to load a video into <Video>, you may want to check if the video can be decoded by the browser. This can be done using Mediabunny.
export const canDecode = async (src: string | Blob) => {
const input = new Input({
formats: ALL_FORMATS,
source: typeof src === 'string' ? new UrlSource(src) : new BlobSource(src),
});
try {
await input.getFormat();
} catch {
return false;
}
const videoTrack = await input.getPrimaryVideoTrack();
if (videoTrack && !(await videoTrack.canDecode())) {
return false;
}
const audioTrack = await input.getPrimaryAudioTrack();
if (audioTrack && !(await audioTrack.canDecode())) {
return false;
}
return true;
};