Video in browser load before playing

Hello everyone. I have been using a template node to load and play a video. Most times the video plays and will keep playing but occasionally and more frequently it look like the video starts but dowes not finish loading. It almost looks like it was paused. I'm wondering if I need to wait until file is loaded before playing. Here is a sample of what is in the template node. Can someone help with how to wait for a time or until file is loaded before play is executed?

<div>
         <video id="video" width="95%" heigth="95%" video loop="loop"></video>
</div>

<script> 
    (function(scope) {
        // Watch for messages being send to this template node
        scope.$watch('msg', function (msg) {      
            if (msg) {

                var video = document.getElementById('video');
                video.src = msg.payload;

                
                video.play();
            }       
         }); 
    })(scope); 
</script>

Thanks

Maybe you should need to check that the msg.payload has the correct content. As it is written, any msg.payload that arrives will trigger video.play()

Maybe you have some other msg arriving that can disturb?

Also note that browsers generally no longer allow video's to auto-start unless they are muted or unless the user has interacted with the page before the video starts.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.