Merge pull request #191 from itsgareth/fix/ios-background-play
fix: restore iOS background play by detecting iOS before UA spoof
This commit is contained in:
commit
37f4ffb30f
3 changed files with 9 additions and 4 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<script>
|
<script>
|
||||||
|
// Capture real iOS state before spoofing (needed for background audio)
|
||||||
|
var _ua = navigator.userAgent.toLowerCase();
|
||||||
|
window.__IS_IOS__ = /iphone|ipad|ipod/.test(_ua) || (_ua.includes('mac') && navigator.maxTouchPoints > 1);
|
||||||
|
|
||||||
// Spoof User-Agent to bypass Google's embedded browser check
|
// Spoof User-Agent to bypass Google's embedded browser check
|
||||||
Object.defineProperty(navigator, 'userAgent', {
|
Object.defineProperty(navigator, 'userAgent', {
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
const audioPlayer = document.getElementById('audio-player');
|
const audioPlayer = document.getElementById('audio-player');
|
||||||
|
|
||||||
// i love ios and macos!!!! webkit fucking SUCKS BULLSHIT sorry ios/macos heads yall getting lossless only
|
// i love ios and macos!!!! webkit fucking SUCKS BULLSHIT sorry ios/macos heads yall getting lossless only
|
||||||
|
// Use window.__IS_IOS__ (set before UA spoof in index.html) so detection works on real iOS.
|
||||||
|
const isIOS = typeof window !== 'undefined' && window.__IS_IOS__ === true;
|
||||||
const ua = navigator.userAgent.toLowerCase();
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
const isIOS = /iphone|ipad|ipod/.test(ua) || (ua.includes('mac') && navigator.maxTouchPoints > 1);
|
|
||||||
const isSafari =
|
const isSafari =
|
||||||
ua.includes('safari') && !ua.includes('chrome') && !ua.includes('crios') && !ua.includes('android');
|
ua.includes('safari') && !ua.includes('chrome') && !ua.includes('crios') && !ua.includes('android');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,9 +137,9 @@ class AudioContextManager {
|
||||||
|
|
||||||
// Detect iOS - skip Web Audio initialization on iOS to avoid lock screen audio issues
|
// Detect iOS - skip Web Audio initialization on iOS to avoid lock screen audio issues
|
||||||
// iOS suspends AudioContext when screen locks, and MediaSession controls don't count
|
// iOS suspends AudioContext when screen locks, and MediaSession controls don't count
|
||||||
// as user gestures to resume it, causing audio to play silently
|
// as user gestures to resume it, causing audio to play silently.
|
||||||
const ua = navigator.userAgent.toLowerCase();
|
// Use window.__IS_IOS__ (set before UA spoof in index.html) so detection works on real iOS.
|
||||||
const isIOS = /iphone|ipad|ipod/.test(ua) || (ua.includes('mac') && navigator.maxTouchPoints > 1);
|
const isIOS = typeof window !== 'undefined' && window.__IS_IOS__ === true;
|
||||||
if (isIOS) {
|
if (isIOS) {
|
||||||
console.log('[AudioContext] Skipping Web Audio initialization on iOS for lock screen compatibility');
|
console.log('[AudioContext] Skipping Web Audio initialization on iOS for lock screen compatibility');
|
||||||
// Don't set isInitialized - let it remain false so isReady() returns false
|
// Don't set isInitialized - let it remain false so isReady() returns false
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue