import processing.core.PApplet;
import codeanticode.glgraphics.GLConstants;
import codeanticode.glgraphics.GLTexture;
import codeanticode.gsvideo.GSMovie;
public class GSVideoLoop extends PApplet {
GSMovie myMovie;
private GLTexture movieTexture;
public void setup() {
size(1100, 600, GLConstants.GLGRAPHICS);
myMovie = new GSMovie(this, "video.mov");
movieTexture = new GLTexture(this);
myMovie.setPixelDest(movieTexture);
myMovie.loop();
}
public void movieEvent(GSMovie myMovie) {
myMovie.read();
}
public void draw() {
if (movieTexture.putPixelsIntoTexture()) {
background(25, 0, 200);
image(movieTexture, 0,0);
}
}
public static void main(String args[]) {
PApplet.main(new String[] { GSVideoLoop.class.getName() });
}
}
package sfda.view.components.video;
import org.mt4j.components.TransformSpace;
import org.mt4j.components.visibleComponents.shapes.MTRectangle;
import codeanticode.gsvideo.GSMovie;
import processing.core.PImage;
import processing.core.PApplet;
public class VideoPlayer3 extends MTRectangle {
private PApplet app;
private GSMovie myMovie,myAlpha;
private PImage movieTexture,alphaTexture;
///////////////////////////////////////////////////////////////////////////////////////
public VideoPlayer3 ( PApplet app, String moviePath,String alphaPath) {
super( app, 400, 400 );
this.setNoFill(true);
this.setNoStroke(true);
this.app = app;
myMovie = new GSMovie(app, moviePath);
movieTexture = new PImage();
myMovie.setPixelDest(movieTexture);
myMovie.setEventHandlerObject(this);
myAlpha = new GSMovie(app, alphaPath);
alphaTexture = new PImage();
myAlpha.setPixelDest(alphaTexture);
myAlpha.setEventHandlerObject(this);
myAlpha.play();
myMovie.loop();
}
///////////////////////////////////////////////////////////////////////////////////////
public void movieEvent(GSMovie myMovie2) {
if (myMovie2==myMovie){
if (myAlpha!=null){
myAlpha.jump((int)myMovie.frame());
myAlpha.read();
}
myMovie.read();
}
}
///////////////////////////////////////////////////////////////////////////////////////
@Override
public void destroy (){
if( myAlpha != null ){
myAlpha.dispose();
myAlpha.delete();
}
myMovie.dispose();
myMovie.delete();
super.destroy();
}
public void updateComponent(long timeDelta){
this.setWidthLocal(myMovie.getSourceWidth());
this.setHeightLocal(myMovie.getSourceHeight());
movieTexture = myMovie.get();
alphaTexture.removeCache(this);
alphaTexture = myAlpha.get();
if(movieTexture.width==alphaTexture.width && movieTexture.height==alphaTexture.height)
movieTexture.mask(alphaTexture);
app.image(movieTexture, this.getPosition(TransformSpace.RELATIVE_TO_PARENT).getX()-this.getWidthXYRelativeToParent()*0.5f, this.getPosition(TransformSpace.RELATIVE_TO_PARENT).getY()-this.getHeightXYRelativeToParent()*0.5f);
}
}