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!

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");
  }
}


1 Like