Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Delay when playing multiple videos at the same time!

$
0
0

Hello! In my project I have to play a string of videos randomly and at the same time, the problem is that very time a new video is added the others, which are already playing, freeze for a second! I´ve read that preloading them could fix this problem but i don´t now how to go about it and if it realy works?

I will live the code i´m working on here hope you can help me out!

// libs:

import processing.video.\*;

// declarations

int $winW = 1920; // window

int $winH = 1080;

int $margin = 20;

int $celsW = 20; // numero de  celulas horizontal

int $celsH = 15; // numero de  celulas vertical

int $celW, $celH;

int $fps = 25;

int $beat = 10; // tempo entre cada video!

//lista de videos

String[] $videoFiles = {

  "1.mov",

  "2.mov"

};

int $frame = 0;

int $vidMax;

Movie[] $videos;

/\*

 \* Main proggy

 \*/

//

// SETUP:

//

void setup() {

  size(1920, 1080);

  background(0);

  frameRate($fps);

  // defenir o tamanho de cada celula

  $celW =  $winW/$celsW;

  $celH =  $celW;

  /\* Init matrix \*/

  $videos = new Movie[$celsW\*$celsH];

  $vidMax = $videoFiles.length;

}

//

// DRAW:

//

void draw() {

  background(0);

  // show something new?

  if ($frame % $beat == 0) {

    int vid = floor(random(0, $vidMax));

    int pos = floor(random(0, $videos.length));

    while ($videos[pos] != null) {

      pos = floor(random(0, $videos.length));

    }

    $videos[pos] = new Movie(this, $videoFiles[vid]);

    $videos[pos].jump(0);

    $videos[pos].noLoop();

    $videos[pos].play();

    println("loading video " + vid + " at position " + pos);

  }

  // read videos:

  for (int i = 0; i < $videos.length; i++) {

    if ($videos[i] != null) {

      if ($videos[i].time() < $videos[i].duration() - 0.1) {

        $videos[i].read();

        int x = (i % $celsW) \* $celW;

        int y = (i / $celsW) \* ($celH+$celsH/3);

//         int y = (i / ($celsH+$celsH/2)) \* ($celH+$celsH/2);

        image($videos[i], x, y, $celW, $celH);

      } else {

        $videos[i] = null;

      }

    }

  }



  $frame++;
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles