06.01.2013 Views

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

Learning Processing: A Beginner's Guide to Programming Images ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

16.3<br />

Recorded Video<br />

Video 281<br />

Displaying recorded video follows much of the same structure as live video. <strong>Processing</strong> ’s video library<br />

only accepts movies in QuickTime format. If your video fi le is a diff erent format, you will either have <strong>to</strong><br />

convert it or investigate using a third party library. Note that playing a recorded movie on Windows does<br />

not require a vdig.<br />

Step 1. Instead of a Capture object, declare a Movie object.<br />

Movie movie;<br />

Step 2. Initialize Movie object.<br />

movie = new Movie(this, "testmovie.mov");<br />

Th e only necessary arguments are this and the movie’s fi lename enclosed in quotes. Th e movie fi le should<br />

be s<strong>to</strong>red in the sketch’s data direc<strong>to</strong>ry.<br />

Step 3. Start movie playing.<br />

Here, there are two options, play( ) , which plays the movie once, or loop( ) , which loops it continuously.<br />

movie.loop();<br />

Step 4. Read frame from movie.<br />

Again, this is identical <strong>to</strong> capture. We can either check <strong>to</strong> see if a new frame is available, or use a callback<br />

function.<br />

Or:<br />

void draw() {<br />

if (movie.available()) {<br />

movie.read();<br />

}<br />

}<br />

void movieEvent(Movie movie) {<br />

movie.read();<br />

}<br />

Step 5. Display the movie.<br />

image(movie,0,0);<br />

Example 16-4 shows the program all put <strong>to</strong>gether.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!