Reputation: 9431
Here is a link to the code that I'm working with. https://github.com/positlabs/lpl-processor/blob/master/lpl_processor/lpl_processor.pde
The problem is that I would like to infer the movie dimensions, but I need to wait until the first frame of the movie is read. When I try to call createGraphics()
anywhere except setup()
, it fails.
Here is a condensed test-case.
import processing.video.*;
Movie movie;
PGraphics graphics;
void setup()
{
size(800, 600);
movie = new Movie(this, "sparkle.mov");
movie.play();
graphics = createGraphics(800, 600); // succeess graphic!
}
void movieEvent(Movie m) {
m.read();
graphics = createGraphics(m.width, m.height); // failure grahic!!
}
And here is the stack trace.
`
java.lang.NullPointerException
at processing.core.PApplet.makeGraphics(PApplet.java:1916)
at processing.core.PApplet.createGraphics(PApplet.java:1872)
at processing.core.PApplet.createGraphics(PApplet.java:1791)
at sketch_141206a.movieEvent(sketch_141206a.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at processing.video.Movie.fireMovieEvent(Unknown Source)
at processing.video.Movie.invokeEvent(Unknown Source)
at processing.video.Movie$2.rgbFrame(Unknown Source)
at org.gstreamer.elements.RGBDataAppSink$AppSinkNewBufferListener.newBuffer(RGBDataAppSink.java:162)
at org.gstreamer.elements.AppSink$2.callback(AppSink.java:184)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:455)
at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:485)
error, disabling movieEvent() for sparkle.mov
`
Upvotes: 0
Views: 294
Reputation: 9431
The correct way to do this is in the draw
function, but it makes initialization a little funky.
Upvotes: 0