Skip to content

Commit 5c0612b

Browse files
committed
Trying to solve some throbbing issues with Safari iPhone
Glitches on Safari iOS #138
1 parent bee6a87 commit 5c0612b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/document_cpu.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,25 @@ export const DocumentCPU = {
142142
}
143143

144144
if (audiotag.fastSeek) {
145-
// HTMLAudioElement.fastSeek() is an experimental but really fast function.
145+
// HTMLAudioElement.fastSeek() is an experimental but really fast function. Firefox only, alas
146146
audiotag.fastSeek(seconds);
147147
} else {
148148
try {
149+
const settime = () => {audiotag.currentTime = seconds;} ;
149150
// Browsers may not have fastSeek but can set currentTime
150-
audiotag.currentTime = seconds;
151+
if (audiotag.readyState >= audiotag.HAVE_CURRENT_DATA) {
152+
// Chrome, Edge, and any other webkit-like except Safari on iPhone
153+
settime();
154+
} else {
155+
// Safari on iPhone is totally incumbent on media throbbing
156+
// See https://github.com/dascritch/cpu-audio/issues/138#issuecomment-816526902
157+
// and https://stackoverflow.com/questions/18266437/html5-video-currenttime-not-setting-properly-on-iphone
158+
audiotag.load();
159+
settime();
160+
if (audiotag.currentTime < seconds){
161+
audiotag.addEventListener("loadedmetadata", settime, {once:true});
162+
}
163+
}
151164
} catch(e) {
152165
// except sometimes, so you must use standard media fragment
153166
audiotag.src = `${audiotag.currentSrc.split('#')[0]}#t=${seconds}`;

0 commit comments

Comments
 (0)