diff --git a/index.html b/index.html
index 135649c..c6a22db 100644
--- a/index.html
+++ b/index.html
@@ -967,6 +967,8 @@
const playAudioWithFallback = (audio, options = {}) => {
if (!audio) return;
const { deferOnIOS = false } = options;
+ const isHidden = typeof document !== 'undefined' && document.hidden;
+ const shouldDefer = deferOnIOS && IS_IOS && !isHidden;
const doPlay = () => {
const playPromise = audio.play();
if (playPromise && typeof playPromise.catch === 'function') {
@@ -978,7 +980,7 @@
}
};
- if (deferOnIOS && IS_IOS) {
+ if (shouldDefer) {
const onCanPlay = () => {
audio.removeEventListener('canplay', onCanPlay);
doPlay();
@@ -1221,7 +1223,9 @@
const triggerAutoNext = () => {
if (autoAdvanceLockRef.current) return;
autoAdvanceLockRef.current = true;
- playNext(true, { immediate: !IS_IOS, deferOnIOS: IS_IOS });
+ const isHidden = typeof document !== 'undefined' && document.hidden;
+ const immediate = IS_IOS || isHidden;
+ playNext(true, { immediate, deferOnIOS: IS_IOS });
};
const isNearEnd = () => {
@@ -1377,7 +1381,9 @@
}
if (auto) {
- autoNextPendingRef.current = true;
+ autoNextPendingRef.current = !options.immediate;
+ } else {
+ autoNextPendingRef.current = false;
}
let nextIdx;