# I get a TypeError: f.default.\_friendlyAutoplayError randomly when calling video.loop()

**URL:** https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675
**Category:** p5.js
**Created:** [February 8, 2021, 8:22pm UTC](https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675 "2021-02-08T20:22:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sandersturing](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@sandersturing](https://discourse.processing.org/u/sandersturing)
#### Post date: [February 8, 2021, 8:22pm UTC](https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675/1 "2021-02-08T20:22:21Z")

</div>

Can’t really find anything when googling the error. When I call `video.loop` (actually, I’m calling a couple of really small videos (together smaller than 2MB), like so:

```auto
for(let i = 0; i < videos.length; i++){
    videos[i].loop();
}

```

I get a `TypeError: f.default._friendlyAutoplayError` (in p5.min.js:3) randomly (as in on loading the page) on that line.

I use `createVideo` to create the videos in preload:

```auto
function preload(){
    for(let i = 0; i < videoNames.length; i++){
        videos[i] = createVideo(videoNames[i]);
    }
}

```

75% of the time the code just works by the way. At random moments I get this error and can’t play the videos. If I console.log the videos I do get a result and the object seems to be loaded.

Any ideas what this error is and where it comes from?

---

<div class="post-metadata">

### Author: ![sandersturing](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@sandersturing](https://discourse.processing.org/u/sandersturing)
#### Post date: [February 8, 2021, 8:27pm UTC](https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675/2 "2021-02-08T20:27:50Z")

</div>

I thought it was a good idea to load the full P5, instead of the minified version. This gives me the following error (for all videos):

`p5.js says: The media that tried to play (with 'video.mp4') wasn't allowed to by this browser, most likely due to the browser's autoplay policy. Check out https://developer.mozilla.org/docs/Web/Media/Autoplay_guide for more information about why.`

Of course, this is BS, since the same video(s) play perfectly on 75% of the page loads…

---

<div class="post-metadata">

### Author: ![Pr0tonX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pr0tonx/32/2590_2.png) [@Pr0tonX](https://discourse.processing.org/u/Pr0tonX)
#### Post date: [February 9, 2021, 3:07pm UTC](https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675/3 "2021-02-09T15:07:04Z")

</div>

It is a friendly error to warn you that you can’t autoplay medias on your browser because of the restrictions you’ve settled. On Firefox, you can see this when you block every autoplay :  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/fbd0ee3fe298d778af3778e56a885fc35a2a20ae.png)  
You can click on the “play” button and change the setting for your local port to avoid it

---

<div class="post-metadata">

### Author: ![sandersturing](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@sandersturing](https://discourse.processing.org/u/sandersturing)
#### Post date: [February 21, 2021, 4:51pm UTC](https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675/4 "2021-02-21T16:51:38Z")

</div>

Hey Pr0tonX,

Thanks for looking with me. I understand the error, but shouldn’t it then display every time? Now it just shows up randomly about 25% of the time on page load, the rest of the time everything plays fine (without me changing anything. Same videos, same code, same browser, same session etc.).  
I have the feeling it just can’t handle displaying so many videos and the error is not really connected.

Anyway, I just think playing a lot of videos suck in whatever browser or program you’re trying to do it. I only could get it to work reliable in Chrome anyway. Safari stopped looping after a while, and Firefox didn’t do anything at all.  
I changed all files to GIFS (which unfortunately are a lot bigger in file size) and everything runs quite smoothly in all browsers.

---

<div class="post-metadata">

### Author: ![Pr0tonX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pr0tonx/32/2590_2.png) [@Pr0tonX](https://discourse.processing.org/u/Pr0tonX)
#### Post date: [February 23, 2021, 10:53pm UTC](https://discourse.processing.org/t/i-get-a-typeerror-f-default-friendlyautoplayerror-randomly-when-calling-video-loop/27675/5 "2021-02-23T22:53:35Z")

</div>

I can’t say, I cannot reproduce your error ; but yes running videos can be ressource intensive if you don’t have a decent GPU (I think browsers use to enable it ) so it can causes troubles if you try to load a lot, but it is only asumption for now.

Maybe one of your videos creates an issue while loading in your preload, and the error fallback can be wrong.  
Did you try to load your videos asynchronously ? Using the fallback of the `createVideo` function ? It might avoid some loading issues in case it is the point :

```auto
const videoPaths = ['cool.mp4', 'banana.mp4', 'super.mp4'];
const videos = []
function preload(){
    const loadVideos = (i = -1) => {
       i ++;
       if (i <= videoPaths.length - 1){
             videos[i] = createVideo(videoPaths[i], loadVideo(i));
      } else {
             videos[i] = createVideo(videoPaths[i]);
      }
      
   }
}

```
