Hi,
I’m making a VR video player and trying to swap out the video on the sphere without a few seconds of black screen while the new video loads. My plan has been to load a dummy mesh with the texture and swap them out, ,then dispose of the dummy mesh. Unfortunately I can’t seem to dispose of the previous videos, cos after a few videos I’m getting a massive slow down and lots of resource errors - and this is on desktop so I hate to think what’s going to happen on mobile.
This is my current working code:
private function updateVideoSphere():void
{
//if(_currentScene)
//clearCurrentScene();
if(!panoVideoMesh){
trace("CREATING INTIAL VIDEO");
sphereGeometry = new SphereGeometry(5000, 64, 48);
texture2DBase = new NativeVideoTexture(Model.config.getAssetUrl(Model.currentScene.video), true, true);
texture2DBase.player.play();
texture2DBase.addEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
textureMaterial = new TextureMaterial(texture2DBase, false, false, false);
panoVideoMesh = new Mesh(sphereGeometry, textureMaterial);
panoVideoMesh.scaleX *= -1;
panoVideoMesh.rotate(Vector3D.Y_AXIS,-90);
cameraController = new HoverController(camera);
ready = true;
scene.addChild(panoVideoMesh);
}
else
{
trace("REPLACING VIDEO");
//texture2DBase.player.pause();
texture2DBaseNext = new NativeVideoTexture(Model.config.getAssetUrl(Model.currentScene.video), true, true);
texture2DBaseNext.addEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
textureMaterialNext = new TextureMaterial(texture2DBaseNext, false, false, false);
panoVideoMeshNext = new Mesh(sphereGeometry, textureMaterialNext);
scene.addChild(panoVideoMeshNext);
//panoVideoMeshNext.visible = false;
}
}
private function onVideoStart(e:Event):void{
if(panoVideoMeshNext){
ready = false;
TextureMaterial(panoVideoMesh.material).texture = texture2DBaseNext;
texture2DBaseNext.removeEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
scene.removeChild(panoVideoMeshNext);
panoVideoMeshNext.dispose();
//textureMaterialNext.dispose();
//texture2DBaseNext.dispose();
ready = true;
if(texture2DBase){
texture2DBase.dispose();
texture2DBase = null;
}
}
else
texture2DBase.removeEventListener(NativeVideoTexture.VIDEO_START,onVideoStart);
}
And it kind of works, I just can’t see how to properly dispose of the video after the change without destroying the current video.
Any clues gratefully received.