Multivideo player - breaks when replaying from start

Hi. I am trying to create a multivideo player and have based mostly on this answer. I’m using Processing on Debian 10 with the beta video library 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? :slight_smile: Thank you!


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(){
  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

void draw(){
  if (playlist[currentMovieIndex].available()) {
  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
      if (currentMovieIndex > (numMovies-1)) {
        currentMovieIndex = 0;
        //use this to tell the next movie in the list to play
      println("movie at index " + currentMovieIndex + " started");

1 Like