Bug 1788596 - Force audio element load to avoid edge case on media error handling r=alwu

Differential Revision: https://phabricator.services.mozilla.com/D158076
This commit is contained in:
Alexandre Lissy 2022-10-06 06:14:10 +00:00
parent ce09ecf9e1
commit efbdf623dc

View File

@ -186,16 +186,26 @@ async function checkAudioDecoder(
}
};
audio.addEventListener("timeupdate", timeUpdateHandler, { once: true });
const startPlaybackHandler = async ev => {
ok(
await audio.play().then(
_ => true,
_ => false
),
"audio started playing"
);
audio.addEventListener("timeupdate", timeUpdateHandler, { once: true });
};
audio.addEventListener("canplaythrough", startPlaybackHandler, {
once: true,
});
});
ok(
await audio.play().then(
_ => true,
_ => false
),
"audio started playing"
);
// We need to make sure the decoder is ready before play()ing otherwise we
// could get into bad situations
audio.load();
return checkPromise;
}