# Looping several videos

**URL:** <https://discourse.processing.org/t/looping-several-videos/43854>\
**Category:** Coding Questions\
**Created:** [February 7, 2024, 9:14pm UTC](https://discourse.processing.org/t/looping-several-videos/43854 "2024-02-07T21:14:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![uili](https://avatars.discourse-cdn.com/v4/letter/u/b38774/32.png) [@uili](https://discourse.processing.org/u/uili)\
**Post date:** [February 7, 2024, 9:14pm UTC](https://discourse.processing.org/t/looping-several-videos/43854/1 "2024-02-07T21:14:21Z")

</div>

[https://editor.p5js.org/guillermo\_d/sketches/jMAtBLViX](https://editor.p5js.org/guillermo_d/sketches/jMAtBLViX)  
Hello!! I have three videos in this sketch, but i only get the first one to loop. I need to make a loop with the three videos. I’ve been trying different options and can’t find a solution. Can anybody help me?  
thanks

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 7, 2024, 11:32pm UTC](https://discourse.processing.org/t/looping-several-videos/43854/2 "2024-02-07T23:32:38Z")

</div>

I don’t know

did you call `videoEnded()` ?

😉

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [February 19, 2024, 11:54am UTC](https://discourse.processing.org/t/looping-several-videos/43854/3 "2024-02-19T11:54:20Z")

</div>

Hi @uili,

on setup do just …

```auto
  // ...
  videos = [conejo49, conejodis, conejosv];
  for (let video of videos) {
    video.size(230, 230); // Establecer tamaño
    video.onended(videoEnded); // Asignar evento al finalizar el video
  }
  videos[currentVideoIndex].show();
  videos[currentVideoIndex].play();
  // ...

```

and for videoEnded simply …

```auto
function videoEnded() {
    videos[currentVideoIndex].stop(); // Ocultar los videos
    videos[currentVideoIndex].hide(); // Ocultar los videos
    currentVideoIndex = (currentVideoIndex + 1) % videos.length;
    videos[currentVideoIndex].show();
    videos[currentVideoIndex].play();
}

```

Cheers  
— mnse
