Accessing two appended video-children (for parallel seconds-handling)

Cf the tutorial of ‘Video textures’. Within the scriptwise starting point of

VideoTexture.prototype.update = function(dt) {
    // Transfer the latest video frame to the video texture
    for(var i =0; i<document.body.childNodes.length; i++){
            if(i===38){this.vtToGrey = document.body.childNodes[i].src;} /
    }      
    
    this.videoTexture.upload();
};

I am able to access the childnodes of the other video by .src
… but as I wish to handle the currentTime on the two different videos separately/at the same time:
https://playcanvas.com/editor/scene/1167969

  • trouble rise, where I specifically seem to miss the option of initializing the ‘video’ object correctly at the vtGrey-script?

err-msg: Uncaught TypeError: this.videoDomGrey.play is not a function

(I have already tried to initialize ‘video’ as ‘videoGrey’, which messes up the video.load(); calls [there seem to be some built-in code relating to ‘.video’, as two simultaneoulsy played video, maybe wasn’t foreseen api-wise (?)])

Hi @Thomas_Due_Nielsen,

I’m seeing that you’re declaring this.vtToGrey as null in the initialize function of the video-texture.js file and then this.videoGreyDom as null in the initialize function of VtGrey.

You then look up these objects in the update loop. Is there a reason you’re not just defining them in the initialize group and calling them later? It seems really expensive to be constantly looking up entities by name.

Also, looking at your for loop in the video-texture.js file. It doesn’t look like you’re binding the scope of the script to that loop. Meaning that this.vtToGrey will return null outside of that loop because that is how it was defined in initialize.

1 Like

the reason why I am using the .update, is caused to the script loading order:

  • if not taking that into account, I might not find the correct childNodes (both the videoTexture and vtGrey scripts {on both the video-entities - and yes need to find those …ByName
    image
    }).

But I am always ready to backtrack any mishap, so could you maybe do a better structure for the video planes+scripts handling then?

Hi @Thomas_Due_Nielsen,

I’m a bit pressed for time at the moment, so I can’t take too much a look, but if I were doing something similar, I would add entity attributes to the vtGrey and vtGreen scripts that are populated in the editor or defined in initialize that define the normal video entity.

Then to make my video elements easier to find, I would give them an ID and define them in initiaalize wherever I might need them. I think the main functional problem here is that in the update function, you define videoDomGrey as this.vtToGrey = document.body.childNodes[i].src As that returns a string, there is no function to play the video. You would have to call the function on the DOM element itself.

Like I said, I don’t have too much time today, but I hope this is helpful.

ok, thx anyway :slight_smile:@yauStar had also a thread where he spoke about ‘multiple DOM videos were not available on mobile platforms’ anyways (apparently)
Trying something else