# Multivideo player - breaks when replaying from start

**URL:** <https://discourse.processing.org/t/multivideo-player-breaks-when-replaying-from-start/21645>\
**Category:** Libraries\
**Created:** [June 7, 2020, 8:48am UTC](https://discourse.processing.org/t/multivideo-player-breaks-when-replaying-from-start/21645 "2020-06-07T08:48:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![overFlow](https://avatars.discourse-cdn.com/v4/letter/o/848f3c/32.png) [@overFlow](https://discourse.processing.org/u/overFlow)\
**Post date:** [June 7, 2020, 8:48am UTC](https://discourse.processing.org/t/multivideo-player-breaks-when-replaying-from-start/21645/1 "2020-06-07T08:48:53Z")

</div>

Hi. I am trying to create a multivideo player and have based mostly on [this answer](https://stackoverflow.com/questions/31832499/playing-multiple-videos-in-processing/31916948#31916948). I’m using Processing on Debian 10 with the [beta video library](https://github.com/processing/processing-video/releases/tag/r3-v2.0-beta1) recommended for Linux.

Playing my 4 videos the first time works fine, but when going back to the first video, the videos start playing one over another and play for few seconds only. I assumed it was something in bringing back the `currentMovieIndex` variable to 0, so I tried to rewrite the code in several ways, but the effect is always the same. Can anybody see the bug that I’m not seeing? 🙂 Thank you!

```auto
import processing.video.*;

int numMovies = 4;//total number of movies
Movie[] playlist = new Movie[numMovies];//a list of all the movie objects, currently not initialized
int currentMovieIndex = 0;//index of the movie currently playing

float movieEndDuration = 0.029719;//a 'magic number' helpful to find out when a movie finishes playing

void setup(){
  size(640,360);
  frameRate(30);
  for(int i = 0 ; i < numMovies; i++){
    //initialize each movie object in the list
    playlist[i] = new Movie(this,"vid-"+i+".mp4");//new Movie(this, "vid-"+(i+1)+".mp4");
  }
  //start playback
  playlist[currentMovieIndex].play();
}

void draw(){
  background(0);
  if (playlist[currentMovieIndex].available()) {
    playlist[currentMovieIndex].read();
  }
  image(playlist[currentMovieIndex],0,0);
  if((playlist[currentMovieIndex].time() + movieEndDuration) >= playlist[currentMovieIndex].duration()){
      println("movie at index " + currentMovieIndex + " finished playback");
      //go to the next movie index
      currentMovieIndex = (currentMovieIndex+1);
        //increment by one buy use % to loop back to index 0 when the end of the movie array is reached
      println(currentMovieIndex);
      if (currentMovieIndex > (numMovies-1)) {
        currentMovieIndex = 0;
      }
        //use this to tell the next movie in the list to play
      playlist[currentMovieIndex].play();
      println("movie at index " + currentMovieIndex + " started");
  }
}

```
