From 15749d072c42fad7b9a13e89a7715714d762c971 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 15 Aug 2012 04:34:41 +0000 Subject: [PATCH] Updated Movie examples --- .../video/examples/Movie/Frames/Frames.pde | 26 +++++++++---------- .../video/examples/Movie/Loop/Loop.pde | 2 +- .../examples/Movie/Pixelate/Pixelate.pde | 19 +++++++------- .../video/examples/Movie/Reverse/Reverse.pde | 24 ++++++++--------- .../video/examples/Movie/Scratch/Scratch.pde | 12 ++++----- .../video/examples/Movie/Speed/Speed.pde | 3 +-- 6 files changed, 41 insertions(+), 45 deletions(-) diff --git a/java/libraries/video/examples/Movie/Frames/Frames.pde b/java/libraries/video/examples/Movie/Frames/Frames.pde index aefbeac68..3f087217d 100644 --- a/java/libraries/video/examples/Movie/Frames/Frames.pde +++ b/java/libraries/video/examples/Movie/Frames/Frames.pde @@ -10,36 +10,38 @@ import processing.video.*; Movie movie; -int newFrame = 0; +int newFrame; PFont font; void setup() { - size(320, 240); + size(320, 240, P2D); background(0); // Load and set the video to play. Setting the video // in play mode is needed so at least one frame is read // and we can get duration, size and other information from // the video stream. movie = new Movie(this, "station.mov"); - - // Pausing the video at the first frame. movie.play(); - movie.goToBeginning(); - movie.pause(); font = loadFont("DejaVuSans-24.vlw"); textFont(font, 24); } void movieEvent(Movie movie) { - movie.read(); + movie.read(); } void draw() { + if (frameCount == 5) { + // Trick to force start at frame 0... + newFrame = 0; + setFrame(newFrame); + } + image(movie, 0, 0, width, height); fill(240, 20, 30); - text(getFrame() + " / " + (getLength() - 1), 10, 30); + text(getFrame() + " / " + (getLength() - 1), 10, 30); } void keyPressed() { @@ -51,18 +53,17 @@ void keyPressed() { } } - setFrame(newFrame); } int getFrame() { - return ceil(movie.time() * movie.getSourceFrameRate()) - 1; + return ceil(movie.time() * movie.frameRate) - 1; } void setFrame(int n) { movie.play(); - float srcFramerate = movie.getSourceFrameRate(); + float srcFramerate = movie.frameRate; // The duration of a single frame: float frameDuration = 1.0 / srcFramerate; @@ -82,6 +83,5 @@ void setFrame(int n) { } int getLength() { - return int(movie.duration() * movie.getSourceFrameRate()); + return int(movie.duration() * movie.frameRate); } - diff --git a/java/libraries/video/examples/Movie/Loop/Loop.pde b/java/libraries/video/examples/Movie/Loop/Loop.pde index af80646ab..8168d33ba 100644 --- a/java/libraries/video/examples/Movie/Loop/Loop.pde +++ b/java/libraries/video/examples/Movie/Loop/Loop.pde @@ -11,7 +11,7 @@ import processing.video.*; Movie movie; void setup() { - size(640, 480); + size(640, 480, P2D); background(0); // Load and play the video in a loop movie = new Movie(this, "station.mov"); diff --git a/java/libraries/video/examples/Movie/Pixelate/Pixelate.pde b/java/libraries/video/examples/Movie/Pixelate/Pixelate.pde index c835b05cf..2249a4a67 100644 --- a/java/libraries/video/examples/Movie/Pixelate/Pixelate.pde +++ b/java/libraries/video/examples/Movie/Pixelate/Pixelate.pde @@ -15,7 +15,7 @@ Movie myMovie; color myMovieColors[]; void setup() { - size(640, 480); + size(640, 480, P2D); noStroke(); background(0); myMovie = new Movie(this, "station.mov"); @@ -28,22 +28,23 @@ void setup() { // Read new values from movie void movieEvent(Movie m) { m.read(); - m.loadPixels(); - - for (int j = 0; j < numPixels; j++) { - for (int i = 0; i < numPixels; i++) { - myMovieColors[j*numPixels + i] = m.get(i, j); - } - } } // Display values from movie void draw() { + myMovie.loadPixels(); + + for (int j = 0; j < numPixels; j++) { + for (int i = 0; i < numPixels; i++) { + myMovieColors[j*numPixels + i] = myMovie.get(i, j); + } + } + for (int j = 0; j < numPixels; j++) { for (int i = 0; i < numPixels; i++) { fill(myMovieColors[j*numPixels + i]); rect(i*blockSize, j*blockSize, blockSize-1, blockSize-1); } } -} +} \ No newline at end of file diff --git a/java/libraries/video/examples/Movie/Reverse/Reverse.pde b/java/libraries/video/examples/Movie/Reverse/Reverse.pde index 883b39567..c1308fd0a 100644 --- a/java/libraries/video/examples/Movie/Reverse/Reverse.pde +++ b/java/libraries/video/examples/Movie/Reverse/Reverse.pde @@ -19,7 +19,7 @@ Movie myMovie; boolean speedSet = false; void setup() { - size(320, 240); + size(320, 240, P2D); background(0); myMovie = new Movie(this, "balloon.ogg"); myMovie.play(); @@ -30,18 +30,16 @@ void movieEvent(Movie myMovie) { } void draw() { - if (myMovie.ready()) { - if (!speedSet) { - // Setting the speed should be done only once, - // this is the reason for the if statement. - speedSet = true; - myMovie.goToEnd(); - // -1 means backward playback at normal speed. - myMovie.speed(-1.0); - // Setting to play again, since the movie stop - // playback once it reached the end. - myMovie.play(); - } + if (!speedSet) { + // Setting the speed should be done only once, + // this is the reason for the if statement. + speedSet = true; + myMovie.jump(myMovie.duration()); + // -1 means backward playback at normal speed. + myMovie.speed(-1.0); + // Setting to play again, since the movie stop + // playback once it reached the end. + myMovie.play(); } image(myMovie, 0, 0, width, height); } \ No newline at end of file diff --git a/java/libraries/video/examples/Movie/Scratch/Scratch.pde b/java/libraries/video/examples/Movie/Scratch/Scratch.pde index 513b4dc60..4768b5e86 100644 --- a/java/libraries/video/examples/Movie/Scratch/Scratch.pde +++ b/java/libraries/video/examples/Movie/Scratch/Scratch.pde @@ -11,14 +11,14 @@ import processing.video.*; Movie movie; void setup() { - size(640, 480); + size(640, 480, P2D); background(0); movie = new Movie(this, "station.mov"); // Pausing the video at the first frame. movie.play(); - movie.goToBeginning(); + movie.jump(0); movie.pause(); } @@ -30,10 +30,8 @@ void draw() { // A new time position is calculated using the current mouse location: float f = constrain((float)mouseX / width, 0, 1); float t = movie.duration() * f; - if (movie.ready()) { - movie.play(); - movie.jump(t); - movie.pause(); - } + movie.play(); + movie.jump(t); + movie.pause(); image(movie, 0, 0, width, height); } \ No newline at end of file diff --git a/java/libraries/video/examples/Movie/Speed/Speed.pde b/java/libraries/video/examples/Movie/Speed/Speed.pde index 3f5b2090b..cb904d1af 100644 --- a/java/libraries/video/examples/Movie/Speed/Speed.pde +++ b/java/libraries/video/examples/Movie/Speed/Speed.pde @@ -11,7 +11,7 @@ import processing.video.*; Movie movie; void setup() { - size(320, 240); + size(320, 240, P2D); background(0); movie = new Movie(this, "balloon.ogg"); movie.loop(); @@ -32,4 +32,3 @@ void draw() { fill(240, 20, 30); text(nfc(newSpeed, 2) + "X", width - 80, 30); } -