Skip to content

fix: resume AudioContext on iOS to enable music playback (#2530)#2927

Open
sungdark wants to merge 6 commits into
FreezingMoon:masterfrom
sungdark:bounty/2530-no-music-iphone
Open

fix: resume AudioContext on iOS to enable music playback (#2530)#2927
sungdark wants to merge 6 commits into
FreezingMoon:masterfrom
sungdark:bounty/2530-no-music-iphone

Conversation

@sungdark

Copy link
Copy Markdown

Summary

On iOS Safari, the Web Audio API's AudioContext is created in a suspended state. Audio playback (both via Web Audio API for SFX and HTMLAudioElement for music) is blocked until the AudioContext is resumed via a user gesture.

Changes

src/sound/soundsys.ts:

  • Added _audioContextResumed flag to track whether the AudioContext has been resumed
  • Added ensureAudioContextResumed() method that checks if context state is 'suspended' and calls context.resume()
  • Set up one-time document listeners (click, touchstart, keydown) in the SoundSys constructor to automatically resume AudioContext on the first user interaction
  • Called ensureAudioContextResumed() before playMusic(), playSFX(), playHeartBeat(), and playShout() to ensure all audio works on iOS

Testing

This fix enables:

  • Background music playback on iOS/iPhone Chrome
  • Sound effects on iOS
  • Heartbeat and shout sounds on iOS

Bounty: #2530 - no music on iPhone | 7 XTR
Payment address: eB51DWp1uECrLZRLsE2cnyZUzfRWvzUzaJzkatTpQV9

sungdark and others added 6 commits March 27, 2026 13:02
Issue: Touching hexagons on Android triggers hover behavior first,
requiring users to tap twice to perform an action.

Fix: Detect touch input via pointer.pointerType and:
- Skip hover effects for touch (onInputOver returns early for touch)
- Handle touch input directly in onInputDown (calls onConfirmFn)
- Skip onInputOut hover-off for touch (no hover was shown)
- Skip onInputUp for touch (already handled in onInputDown)

This makes touch interaction on Android feel immediate and responsive,
matching the expected single-tap behavior.
- Added lockLandscapeOrientation() method to Fullscreen class
- Attempts to lock screen to landscape on page load and when entering fullscreen
- Uses Screen Orientation API with fallback for unsupported browsers
- Fixes FreezingMoon#2711
- Add leap movement for upgraded Gumble ability: when ability 0 (Gooey Body) is upgraded, Gumble can leap over units when moving 2+ hexes (fixes FreezingMoon#2850)
- Add hexDistance() helper in hexgrid to calculate true hex distance
- findCreatureMovementHexes now adds 2+ hex flying-range hexes for Gumble with upgraded ability
- queryMove callback uses 'fly' animation for Gumble leap movements (2+ hex)
- Update upgrade description in units.ts: 'Can leap over units when moving 2+ hexes.'
…d orientation change

- Add orientation change listener to re-lock landscape when user rotates device
- Call lockLandscapeOrientation() when starting a game (startGame)
- Call lockLandscapeOrientation() when starting a match (startMatchButton)
- Existing calls on page load and fullscreen toggle preserved

This ensures the game is locked to landscape orientation whenever the user
interacts with the game, not just on initial page load or fullscreen entry.
…zingMoon#2530)

On iOS Safari, AudioContext is created in suspended state and requires
user interaction to resume. This commit:

- Adds ensureAudioContextResumed() method that checks if context state
  is 'suspended' and calls context.resume()
- Sets up one-time document listeners (click, touchstart, keydown) in
  the SoundSys constructor to resume AudioContext on first user gesture
- Calls ensureAudioContextResumed() before playMusic(), playSFX(),
  playHeartBeat(), and playShout() to ensure audio works on iOS

Fixes: no music on iPhone FreezingMoon#2530
@vercel

vercel Bot commented Mar 27, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the FreezingMoon Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant