mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
100.72k stars 35.22k forks source link

PositionalAudio doesnt work on VisionOS in VR #27779

Open marwie opened 5 months ago

marwie commented 5 months ago

Description

PositionlAudio is not working on vision OS (simulator) when entering VR

Reproduction steps

  1. Open webaudio-orientation example and add the VR button
  2. Start server
  3. Open in Safari on VisionOS or Simulator (make sure you have WebXR flags enabled)
  4. Click Play - note audio is starting
  5. Click Enter VR button - note audio is not playing

Code

https://github.com/needle-tools/three.js/commit/1064ee0fb487b2b0e208b5b1d6578473c6e4b137

Live example

https://uploads.needle.tools/bugreports/threejs%20positional%20audio/examples/webaudio_orientation

Screenshots

No response

Version

160

Device

Headset

Browser

Safari

OS

No response

hybridherbst commented 5 months ago

@mrdoob Do you happen to have any idea here?

mrdoob commented 5 months ago

Hmm... If the Vision Pro is still at my desk tomorrow I'll have a look 👀

mrdoob commented 4 months ago

I tried this the other day.

I think it has to be a Safari bug because I noticed the audio did get filtered when leaving VR.

hybridherbst commented 4 months ago

Thanks for trying. So you think it's a WebAudio bug on their end? Regular HTML audio elements continue playing just fine it seems.

mrdoob commented 4 months ago

I think so yeah.

hybridherbst commented 4 months ago

OK, Ada confirmed it to be a bug and restarting the audio context is a workaround for now:

Is it ok if I keep this issue open until the root cause is fixed, even with no actionable item on three.js side?

mrdoob commented 4 months ago

That's okay 👍

hybridherbst commented 4 months ago

Workaround a customer found today:

const ctx = AudioContext.getContext();
ctx.addEventListener ("statechange", async () => {
    if (ctx.state === "suspended" || ctx.state === "interrupted") {
        ctx.resume().then(() => {
            console. log("AudioContext resumed");
        }).catch((err) => {
            console.error ("AudioContext couldn't be resumed", err);
        });
    }
});
danrossi commented 4 months ago

I'm doing some testing in the simulator and media stops immediately launching xr. And there is no controls to click to play.

marwie commented 4 months ago

I'm doing some testing in the simulator and media stops immediately launching xr. And there is no controls to click to play.

Would you mind trying again here? https://thankful-faint-coral.glitch.me/

danrossi commented 4 months ago

In the webxr session start event, forcing video/audio element playback works. Now need to detect for visionOS to do that. actually you can't detect what platform visionOS is. navigator.platform reports Ipad. So have to check if it's Ipad in WebXR and force play.

hybridherbst commented 4 months ago

@danrossi you can add this code somewhere to work around this bug in VisionOS. No need for navigator checks. https://github.com/mrdoob/three.js/issues/27779#issuecomment-1969913807