Loading a video in another PApplet

edited February 2016 in Library Questions

Hey,

I am trying to load and play a video with the processing core video library, but not in the main PApplet. I would like to have the video loaded and played in another PApplet. Here is a code snippet:

public class MainApplet extends PApplet{
    import processing.core.PApplet;

    public void setup(){
        SecondApplet secondApplet = new SecondApplet(this);
        //...
    }
    //...
}

public class SecondApplet extends PApplet{
    import processing.core.PApplet;
    import processing.video.*;

    public void setup(){
        //...
    }
    public SecondApplet(PApplet mainApplet){
        Movie movie = new Movie(mainApplet,"stringToMovie"):
        //...
    }
    //...
}

Creating an instance of a Movie object with the mainApplet instance is not working.

First, why is that and second, how could that be solved ( besides from putting the functionality into the main Applet ). I had the same problem with the unfolding library, but since this is a third party product it could be different story.

best Arne

Answers

  • Thank you for your reply. I guess I did not put everything right in my question.

    To give a better explanation, the idea is to put some (or most) of the functionality that the mainApplet should have into other classes( I dont like big classes).

    One of the things I want to put into another class is the functionality to play videos. Therefor I have to pass the PApplet I want to draw on right?

  • Another important thing you haven't mentioned is that you're probably not using PDE, but some other IDE like Eclipse, right?

    As you can see from the link I've passed above, the PApplet class is itself inert.
    We still need to "ignite" it via PApplet.main() or PApplet.runSketch().
    If that's not your intention, remove those useless extends PApplet from your classes.
    Instead, you're gonna need to pass the main PApplet reference to them, so they can also access the canvas.

  • Yes, I use Eclipse. my idea was to extend from PApplet to use all the nice processing functions

    public class MainApplet extends PApplet{
        import processing.core.PApplet;
    
        PGraphics pg;
    
        public void setup(){
            SecondApplet secondApplet = new SecondApplet(this);
            pg = createGraphics(width, height);
            //...
        }
        public void draw(){
            secondApplet.draw(pg);
        }
    }
    
    public class SecondApplet extends PApplet{
        import processing.core.PApplet;
        import processing.video.*;
    
        public void setup(){
            //...
        }
        public SecondApplet(PApplet mainApplet){
            Movie movie = new Movie(mainApplet,"stringToMovie"):
            //...
        }
        public void draw(PGraphics pg){
            pg.text("hello world",0,0);
        }
    }
    

    Maybe there is a cleaner way to use the PApplet methods?

  • edited February 2016
    • Most Processing's API demands a canvas in order to draw upon.
    • Like I said, PApplet is an inert class. It's a sitting duck!
    • Only after it is "ignited" and its own canvas is created, along w/ its own "Animation" Thread, it actually becomes Processing! :))
    • If your SecondApplet isn't supposed to have its own canvas, you should remove extends PApplet. It's flatout useless! :>
    • Instead, request a PApplet in its constructor and store it in a field.
    • Then SecondApplet can act upon MainApplet's own canvas. ~O)
  • okay :) then i need to draw like this: pAppletField.pGraphic.rect(...) ?

    I still want to use PGraphics if possible.

  • Once you get a PImage or a PGraphics you don't need the PApplet reference anymore. You'll use the graphics object reference instead.

    PApplet is to access Processing's API. You can also call getGraphics() in order to get canvas' PGraphics reference too.

  • Thank you for your help !

    Unfortunately refactoring my classes helped not solving the problem with the video, but it helped me to find the problem.

    The problem seems to be the gstreamer-java.jar and its dlls for windows. I need to run my program on a 64bit windows . But it seems that there are problems with the gstreamer and 64 bit win.

    [https://forum.processing.org/one/topic/gsvideo-0-7-in-eclipse-on-windows-7-dll-unsatisfiedlinkerror.html](thread about that topic)

    I could not find any help on the github page of processing/video. Is that problem solved by now?

  • That link got at least 3 years or more. It's from the forum before this 1!
    For bugs in the library, better take a look there for yourself:
    https://GitHub.com/processing/processing-video/issues

Sign In or Register to comment.