Preload Question

Hi, I’m a bit confused about what the preload checkbox actually does…

If I have a video asset that is set to preload, I presume it gets downloaded in the initial download…BUT, if I have it NOT set to preload, at what point will it be downloaded…when the video plays?

Does not having the preload checkbox ticked actually prevent the download from the server files when the page initially runs?

Thanks

Found this:
You should use preloading to make sure all the assets you need at the start of your application are present. This will prevent any assets from ‘popping’ in after the application begins.
On:
https://developer.playcanvas.com/en/user-manual/assets/preloading-and-streaming/

You are right about its get downloaded at the start. But if you don’t preload you have to load it in the script yourself.

See this how to preload:
https://developer.playcanvas.com/en/tutorials/using-assets/

Code:
this.app.assets.load( [ Assert Reference ] );

1 Like

Just to add to the above, the way we typically use videos in projects is a special case since it’s being used in a HTML DOM element.

Preload should be unticked and the video DOM element will handle the streaming (if it’s encoded correctly) bit by bit for you. You don’t have to use the assets.load function in this special case

Ok. So according t the developer manual if untick my video asset wont download at start, but instead will start downloading as soon as the entity that references it becomes active.?

In my case its a button entity with the following attribute:
PlayVideoButton_Div.attributes.add(‘video’, { type: ‘asset’});

Just to clarify, the video should start to download as soon as the button entity becomes active?

Thanks.

Yes, or you can manually load the asset before it is used which is recommended otherwise you can get a pop of models/textures/etc appearing in the world.

Video is special case as mentioned before. As it’s being done in HTML and on the DOM, you have to look at the HTML docs instead on how it works: <video>: The Video Embed element - HTML: HyperText Markup Language | MDN

The video would generally start load a buffer when the DOM is added to the HTML document and then continue to load as it plays.

1 Like

My dom is added during the initialize like this…

PlayVideoButton_Div.prototype.initialize = function() {
    // Create the video DOM
    var video = document.createElement('video');
    var videoContainer = document.createElement('div');
    videoContainer.appendChild(video);
...

So does this mean the video will start loading in as soon as this entity is initialized ?

With the code above, yes but only as much as it needs to start playing smoothly. Until the video starts playing, it won’t load more of the video.

1 Like

Perfect. Thanks!