diff --git a/src/document_cpu.js b/src/document_cpu.js index de5e492d..80cfddc2 100644 --- a/src/document_cpu.js +++ b/src/document_cpu.js @@ -142,12 +142,25 @@ export const DocumentCPU = { } if (audiotag.fastSeek) { - // HTMLAudioElement.fastSeek() is an experimental but really fast function. + // HTMLAudioElement.fastSeek() is an experimental but really fast function. Firefox only, alas audiotag.fastSeek(seconds); } else { try { + const settime = () => {audiotag.currentTime = seconds;} ; // Browsers may not have fastSeek but can set currentTime - audiotag.currentTime = seconds; + if (audiotag.readyState >= audiotag.HAVE_CURRENT_DATA) { + // Chrome, Edge, and any other webkit-like except Safari on iPhone + settime(); + } else { + // Safari on iPhone is totally incumbent on media throbbing + // See https://github.com/dascritch/cpu-audio/issues/138#issuecomment-816526902 + // and https://stackoverflow.com/questions/18266437/html5-video-currenttime-not-setting-properly-on-iphone + audiotag.load(); + settime(); + if (audiotag.currentTime < seconds){ + audiotag.addEventListener("loadedmetadata", settime, {once:true}); + } + } } catch(e) { // except sometimes, so you must use standard media fragment audiotag.src = `${audiotag.currentSrc.split('#')[0]}#t=${seconds}`;