HTML5 `<audio>` Element Not Resuming Playback on iOS Safari After Page Refresh
I've hit a wall trying to I'm deploying to production and Quick question that's been bugging me - I'm working with a frustrating scenario where an `<audio>` element on my HTML5 page fails to resume playback after refreshing on iOS Safari... I've implemented a basic audio player, and while it works as expected in most browsers, iOS Safari handles it differently. Below is the relevant code snippet: ```html <audio id="myAudio" controls> <source src="audio-file.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio> <script> const audio = document.getElementById('myAudio'); window.addEventListener('beforeunload', () => { localStorage.setItem('audioCurrentTime', audio.currentTime); }); window.addEventListener('load', () => { const savedTime = localStorage.getItem('audioCurrentTime'); if (savedTime) { audio.currentTime = parseFloat(savedTime); audio.play(); // this doesn't work on iOS Safari } }); </script> ``` When I refresh the page, the audio playback resumes at the saved time, but it doesn't actually play; instead, the audio element appears exploring. The console doesn't show any behavior messages, but I suspect that iOS Safari has strict autoplay policies. I've already checked that user interaction is required to initiate playback, and I've confirmed that the audio file loads correctly. I've tried wrapping the `audio.play()` call in a `setTimeout` to delay it, thinking it might help, but that didn't make any difference. I also verified that the `audio` element has been unmuted, and I'm only testing this on a live server, not in local files, since iOS has restrictions on local file playback. Has anyone else faced similar issues with audio elements on iOS? Any suggestions on how to ensure playback resumes correctly after a refresh would be greatly appreciated! I'm working on a CLI tool that needs to handle this. Any help would be greatly appreciated! I'd really appreciate any guidance on this. This is happening in both development and production on Windows 11. Am I missing something obvious? I'm developing on Windows 11 with Html. Is there a simpler solution I'm overlooking?