Strings of videos play very slowly JAVA

edited September 2014 in Using Processing

Well, I'm trying to display a random video with this code, but I want to know if I can use more String, and how I can write that.

There is another problem: the random video (2Mb, 720x576 resolution, coverted in Internet from .avi to .mov) play in Quicktime very faster than in Processing.

The question is... Is JAVA effective to play videos in PROCESSING?

import processing.video.*; String[] moviesNames = { "1.mov", "2.mov", "3.mov", "4.mov", "7.mov", "6.mov" }; int index = int(random(moviesNames.length));

int colore = 1; 
int fondo = 0;
Movie[] movies;



void setup() {
  size(640, 480, P2D);

  movies = new Movie[moviesNames.length];
  for (int i = 0; i < moviesNames.length; i++) {
    movies[i] = new Movie(this, moviesNames[i]);
  }

}

void draw() {
//background(fondo);

  image(movies[index], 0, 0, width, height);
fill(0,0,0,fondo);
noStroke ();
rect(0, 0, width, height);


}


void movieEvent(Movie _mov) {
  _mov.read();
}

void keyPressed() {
  int k = keyCode;

  if (k == 'Q') fondo=0; pickRandomVideoIndex(); 
    if (k == 'A') {fondo = 255;}

}

void pickRandomVideoIndex() {
  if (movies.length <= 1)  return;

  movies[index].pause(); // pause current video.

  int rnd; // keep picking a new index till got a diff. 1:
  while ( (rnd = (int) random(movies.length)) == index );

  // assign newly picked random value to index:
  movies[index = rnd].loop(); // and start playing it.

}

Answers

  • edited September 2014

    Got 3 tips below. See if you got any improvements:

    1. Use JAVA2D renderer: size(640, 480, JAVA2D);
    2. Adjust frameRate() to match Movie's: frameRate(25);
    3. For a static background-type image, prefer set() in place of image():


    draw() {
      Movie m = movies[index];
      set(width-m.width >> 1, height-m.height >> 1, m);
    }
    

    P.S.: Is that movieEvent() really necessary? Comment that callback function out! (~~)

Sign In or Register to comment.