This is minor bug/issue/clarification, and it is not specific to 5.x.
I ran in to something unexpected using VideoDome, and while researching that, I also saw a potential minor enhancement. I can post these as bugs/features in Github if useful, but I wanted to post here for discussion first in case I am missing something.
1) Bug/Unexpected - VideoDome.clickToPlay
Here is a PG showing what confused me:
If you press ‘d’ key the video dome texture will disappear, however, if you click the blank canvas again you hear the audio from the video start playing again. The reason is that
clickToPlay=true causes VideoDome to register a global
scene.onPointerUp callback (source), and it is never unregistered. The underlying
video element is never fully removed from the DOM (more on that below), and so the global callback starts playback again even though there is no visual video output surface.
Here is PG showing that deleting the global callback prevents the issue:
The correct fix would be to have
VideoDome.dispose unregister this callback.
- A fix should probably also switch to
scene.onPointerObservableinstead of global callback.
- Less important, I would suggest that the onPointerUp listener should be an
addOncelistener. As it is, the video will play/restart on any and every scene pointerUp event. This might be controversial though, and might have non obvious implications for devices that require user event context before playing. (Some previous discussion.)
I believe this bug to not be important beyond the confusion it might cause, because it can be easily avoided by setting
clickToPlay=false and triggering video play manually.
2) Potential Enhancement - VideoDome.dispose and Video Element
It might be assumed that calling VideoDome.dispose would also release the underlying Video element and associated media resources in the browser, but that is currently not the case. That is evident given the previous issue where even though VideoDome.dispose is called, the video element can still be played.
Looking in to this, it seems that getting browsers to release Video resources is not straightforward and browsers aren’t always consistent about it. Based on some SO posts and similar, I came up with this PG to show how it might be done:
Code like this might make sense in VideoTexture.dispose. However, I think testing across various browsers/devices would be important.
(p.s. For anyone testing around this, using these PGs, I’ve found on Chrome/Windows, sometimes the audio stops playing after multiple PG plays or page loads. That can be confusing when you are trying to check if the underlying video playback has stopped. I suspect this is related to the dispose not fully disposing and so browser eventually running out of some low-level resource. Restarting browser usually resolves.)