aframe icon indicating copy to clipboard operation
aframe copied to clipboard

Video playback stops when entering immersive mode in Vision Pro

Open dmarcos opened this issue 1 year ago • 25 comments

Tested on https://aframe.io/aframe/examples/test/video/

The modal in this example generates the user gesture event that triggers video play back as expected while in 2D mode.

When entering immersive mode the video stops playing. On Meta Browser (Quest) the video playback continues as expected.

dmarcos avatar Feb 18 '24 09:02 dmarcos

I confirm this issue, i have a VisionPro. There are different kind of issues in many official examples, if the owner of this project need a feedback, i can report a list. And maybe the main website need a "howto in VisionPro", because WebXR is not active by default (Experimental, extra-flags etc in Settings > App > Safari).

Clodo76 avatar Feb 19 '24 08:02 Clodo76

@Clodo76 Feel free to open additional issues if you found other bugs. Thanks

dmarcos avatar Feb 20 '24 16:02 dmarcos

cc @cabanier @AdaRoseCannon I think Meta browser behavior is the correct one and my hunch is that Safari's one not deliberate but not 100% sure.

dmarcos avatar Feb 20 '24 19:02 dmarcos

This is a known bug sorry. You can start the audio again by resuming an audio context after the session starts.

Although I would prefer for this not to be fixed on the website side and to wait for a fix but I understand if you need to work around.

AdaRoseCannon avatar Feb 20 '24 19:02 AdaRoseCannon

@AdaRoseCannon Thanks so much for the info and the workaround. For A-Frame core I think we will wait for a fix. Not sure if there's any public info but I imagine Safari updates tied to Vision OS releases? Having an approximate time horizon / update cadence will help determine when workarounds are worth vs waiting for a fix. Thanks so much for the help

dmarcos avatar Feb 20 '24 19:02 dmarcos

@Clodo76 Feel free to open additional issues if you found other bugs. Thanks

I made a stylesheet here, i hope can be useful: https://docs.google.com/spreadsheets/d/1Bf8A8x52NlAaI6esGeg2Nd9k_5wBLYuMyorKnPfjTPU/edit#gid=0 (but i don't yet perform Quest3 tests). In VisionPro i tested aframe examples from github, aframe-stereo-component, and general webxr-samples. I'm to newbie about aframe to understand what single issues are real or can be easy fixed, so for now i don't open specific issues and i reply here (i understand maybe offtopic based on this issue title, but are VisionPro issues).

About video (flat or 360 doesn't matter), when i start playback, are played in the browser. When i click "Enter VR", VisionPro ask acknowledge for immersion, when immersion start i see the video still playback, but stop after around a second.

I don't report the colors issue.

An example "pinch to click" for VisionPro can be integrated to fix a lots of unit-cases.

I never find yet a webxr AR example working. Note that VisionPro/Safari show GLTF/GLB in AR space with the < model > html tag, not related to webxr from what i know.

Clodo76 avatar Feb 23 '24 14:02 Clodo76

Note: i made an example with video&audio 360 playback, toggle play/pause with click OR spacebar key. Bluetooth keyboard connected to VisionPro. Load webpage, hit space, video start. "Enter VR" stop it. If i hit spacebar to toggle pause/play state, audio works as expected, video NEVER. If i close VR mode, video is ok in browser. So, seem a texture-update issue, not a "VisionPro automatically stop video playback when enter in VR mode".

Clodo76 avatar Feb 23 '24 14:02 Clodo76

Folks this sounds insane, but I found one site that makes this work. You have to start the playback in immersive mode, but I can confirm it's functional.

Caveat: the journey to the solution is for the brave. It's an adult website... lmao. Tread carefully. https://twitter.com/okpasquale/status/1761038091295371503

psql avatar Feb 23 '24 14:02 psql

@psql Thanks. This is a known bug on Safari's side.

@AdaRoseCannon suggested a workaround You can start the audio again by resuming an audio context after the session starts but we will wait for a browser fix.

dmarcos avatar Feb 23 '24 14:02 dmarcos

@Clodo76 Please file independent issues for any individual problems you encounter. This one is just for the issues concerning video playback stopping when entering immersive mode on Vision Pro. Thanks

FYI, Safari doesn't offer WebXR AR mode yet (immersive-ar). Not a bug but a deliberate decision by Apple

Also A-Frame issues are for bugs in A-Frame core. For 3rd party components please report in their respective repositories. Thanks

There are no issues with texture update to my knowledge. This is confirmed as a Safari bug. Quest browser works as expected

dmarcos avatar Feb 23 '24 15:02 dmarcos

In case it helps someone, this seems to be enough as a workaround in three.js-based apps/engines: As an example, audio works here now on AVP: https://prefrontalcortex.de/digivid/12/

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);
        });
    }
});

hybridherbst avatar Feb 28 '24 21:02 hybridherbst

In the webxr session start event, forcing video playback works. Now need to detect for visionOS to do that.

danrossi avatar Mar 01 '24 18:03 danrossi

Don't have to detect VisionOS but a fix would require code only needed for Vision Pro. For now you can apply workaround described above. On A-Frame side we will wait for a browser fix.

dmarcos avatar Mar 02 '24 02:03 dmarcos

Pseudo code. platform detected goes between Ipad and MacIntel. Maybe just a straight up play is enough but I've tested this.

onSessionStart() {
          //force play for visionOS
          if (this.isIpad) {
           // this.video.play();

            const handlePaused = () => {
                this.video.removeEventListener("pause", handlePaused);
                this.video.play();
            };

            this.video.addEventListener("pause", handlePaused);


        }
}

danrossi avatar Mar 02 '24 06:03 danrossi

@danrossi Hmm, maybe something changed, but the onSessionStart() fix doesn't work for me in the Simulator running visionOS 1.1. I put together a repro using the three.js webxr_vr_video example: https://github.com/jparismorgan/threejs-webxr-vision-pro-video/tree/main

Would be curious if this repro works for anyone else, or if anyone knows what to update it with to get it working? Happy to upstream it as well to fix the three.js example.

https://github.com/jparismorgan/threejs-webxr-vision-pro-video/assets/1396242/745be62e-0fa9-4417-bbf4-1a1ae8d97c62

@hybridherbst, is this fix for the video playback issue? Or just audio? I tried adding this but didn't see any difference:

const ctx = new AudioContext(); // NOTE(paris): this instead of const ctx = AudioContext.getContext(); b/c otherwise we crash with ` 'AudioContext.getContext' is undefined)`.
ctx.addEventListener ("statechange", async () => {
	console.log("state changed: ", ctx.state);
		if (ctx.state === "suspended" || ctx.state === "interrupted") {
				ctx.resume().then(() => {
						console.log("AudioContext resumed");
				}).catch((err) => {
						console.error ("AudioContext couldn't be resumed", err);
				});
		}
});

Thanks for any help!

jparismorgan avatar Apr 03 '24 20:04 jparismorgan

I run all my tests under https to be able to launch webxr from my server on another machine. So try that. I'm trying to get my VR picture in picture hack working for Safari then will release my visionOS changes including transient-pointer controls support.

http-server -p 8084 -S -C /etc/letsencrypt/live/rtc.electroteque.org/cert.pem -K  /etc/letsencrypt/live/rtc.electroteque.org/privkey.pem  ./demo

danrossi avatar Apr 04 '24 01:04 danrossi

Thanks, put it up on Vercel and tested with https, but same error: https://threejs-webxr-vision-pro-video.vercel.app/

jparismorgan avatar Apr 04 '24 12:04 jparismorgan

The AudioContext fix has unfortunately not helped for us - we have no success with audio or video once immersive mode starts. We've filed a bug on the WebKit Bugzilla so that it's in the system :-) https://bugs.webkit.org/show_bug.cgi?id=274385

cgauld avatar May 22 '24 08:05 cgauld

@cgauld can you share code with the workaround?

dmarcos avatar May 22 '24 16:05 dmarcos

Hi @dmarcos unfortunately we don't have a working workaround :-( We had tried the code in the comment above, plus a few others, and nothing was successful.

cgauld avatar May 22 '24 16:05 cgauld

@cgauld Can you share the code of your "not working" workaround with https://glitch.com/~aframe ?

dmarcos avatar May 22 '24 16:05 dmarcos

  const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshBasicMaterial({ visible: false }));
  const meshAudioBg = new THREE.Mesh(
    new THREE.BoxGeometry(1, 1, 1),
    new THREE.MeshBasicMaterial({ visible: false }),
  );
  mesh.add(sound);
  meshAudioBg.add(soundBg);
  scene.add(mesh);
  scene.add(meshAudioBg);
  
  add sound to mesh and apply to scene it working 

hoangman1108 avatar Jun 17 '24 03:06 hoangman1108

Any updates if this has been fixed with VisionOS 2.0? Still struggling to get this to work.

secondpathstudio avatar Oct 18 '24 21:10 secondpathstudio

Please can you make a demo that demonstrates the issue and file a report using feedback assistant including the URL to the demo.

AdaRoseCannon avatar Oct 19 '24 08:10 AdaRoseCannon

@secondpathstudio Provide simple code with https://glitch.com/~aframe to reproduce the issue or it will be hard to help otherwise. Thanks

dmarcos avatar Oct 20 '24 00:10 dmarcos