From efbdf623dc19bf9902bbb5840384e25e31465e50 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Thu, 6 Oct 2022 06:14:10 +0000 Subject: [PATCH] Bug 1788596 - Force audio element load to avoid edge case on media error handling r=alwu Differential Revision: https://phabricator.services.mozilla.com/D158076 --- ipc/glue/test/browser/head.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ipc/glue/test/browser/head.js b/ipc/glue/test/browser/head.js index e54b662906b0..828d919df2f8 100644 --- a/ipc/glue/test/browser/head.js +++ b/ipc/glue/test/browser/head.js @@ -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; }