Skip to content

Commit

Permalink
fix: iOS volume support bug
Browse files Browse the repository at this point in the history
fix #1011
  • Loading branch information
luwes committed Oct 24, 2024
1 parent 59fce18 commit 64940fa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/js/utils/platform-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ export const hasVolumeSupportAsync = async (
if (!mediaEl) return false;
const prevVolume = mediaEl.volume;
mediaEl.volume = prevVolume / 2 + 0.1;
await delay(0);

// iOS Safari doesn't allow setting volume programmatically but it will
// change the volume property for a short time before reverting.
// On heavy sites this can take a while to revert so we need to wait at least
// 100ms to make sure the volume has not changed.
// If there is no change sooner, return false early to minimize UI jank.
for (let i = 0; i < 9; i++) {
await delay(10);
if (mediaEl.volume === prevVolume) return false;
}

await delay(10);
return mediaEl.volume !== prevVolume;
};

Expand Down

0 comments on commit 64940fa

Please sign in to comment.