aframe
aframe copied to clipboard
<a-image> keeps running videos after changing src
setting the src to an <a-image> at runtime to a video and then later to an image the image is loaded but the video keeps playing in the background
- A-Frame Version: 0.8.0
- Platform / Device: All
- Reproducible Code Snippet or URL: https://jsfiddle.net/greggman/jLmz2gpz/
Hi i tried experimenting with this: as a result i got a branch which:
- i think it solved your issue: fiddle
- as well as a SO question regarding swapping video sources: fiddle
The video elements are created and cached in src/system/material.js
i couldn't grab the reference to whats the source when its being changed - so i've kept them in the shader component + added the necessary logic (pause when changing sources, reload when re-using a cached video).
Should i make it into a PR, or wait for some feedback regarding the branch ?
My two cents:
If you mean using a video by selector reference, you have to stop the video yourself, when you change the src, a-image should stop using it but does not manipulate it (since it doesn't really own it)
If you mean by src, then since a video element is created to use it, really a-image should stop and discard the video when src changed (assuming there is no other reference to it) which it probably doesn't (and I would consider a bug)
@machenmusik here its the second case, where the <a-entity> creates the <video> element as i mentioned (here). After its creation the reference is being passed to a callback, but the callback function doesn't use it at all.
The main repo still has this issue. @gftruj ( Hi from years and years in the future) any chance you still have a branch with a working fix? The link is now dead and the fiddles have the same issue when using the most recent aframe version.
@pdbeard I have no clue what happened to the branch, and I'm afraid I'm a bit too busy to re-create it, but I can offer a workaround, which should be working properly if you wait for a video to load before switching (because even if an old one is cached, the new one will be created and play in the background ).
You could also load the videos in threejs, omitting the material system at all.