# Video in browser load before playing

**URL:** https://discourse.nodered.org/t/video-in-browser-load-before-playing/76602
**Category:** General
**Created:** [15 March 2023 15:13 UTC](https://discourse.nodered.org/t/video-in-browser-load-before-playing/76602 "2023-03-15T15:13:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kmarcoux](https://avatars.discourse-cdn.com/v4/letter/k/f9ae1b/32.png) [@Kmarcoux](https://discourse.nodered.org/u/Kmarcoux)
#### Post date: [15 March 2023 15:13 UTC](https://discourse.nodered.org/t/video-in-browser-load-before-playing/76602/1 "2023-03-15T15:13:29Z")

</div>

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?

```auto
<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

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [15 March 2023 15:58 UTC](https://discourse.nodered.org/t/video-in-browser-load-before-playing/76602/2 "2023-03-15T15:58:51Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [15 March 2023 16:07 UTC](https://discourse.nodered.org/t/video-in-browser-load-before-playing/76602/3 "2023-03-15T16:07:41Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [14 May 2023 16:08 UTC](https://discourse.nodered.org/t/video-in-browser-load-before-playing/76602/4 "2023-05-14T16:08:28Z")

</div>

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