Skip to content

Commit

Permalink
Trying to solve some throbbing issues with Safari iPhone
Browse files Browse the repository at this point in the history
Glitches on Safari iOS #138
  • Loading branch information
dascritch committed Apr 9, 2021
1 parent bee6a87 commit 5c0612b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/document_cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 5c0612b

Please sign in to comment.