How to use IntelliJ IDEA to create a working Sketch that can play a video?

Hello,

i am new to processing and this forum so i hope i put my question into the right section.

i managed to get Processing working with Intellij IDEA (Windows 7, Java8, Proceesing 2.2.1). I created a simple sketch that compiles and starts nicely:

public class Simple extends PApplet
{
  /* main method of sketch */
  static public void main(String[] passedArgs)
  {

   String[] appletArgs = new String[]{"demo.Simple"};
    if (passedArgs != null)
    {
      PApplet.main(concat(appletArgs, passedArgs));
    }
    else
    {
      PApplet.main(appletArgs);
    }
  }

  /* sketch initial setup */
  public void setup()
  {
    size(300, 200);
    background(0);
  }

  /* put something on the stage */
  public void draw()
  {
    // Draw gray box

    int d = 20;
    int p1 = d;
    int p2 = p1 + d;
    int p3 = p2 + d;
    int p4 = p3 + d;

    stroke(153);
    line(p3, p3, p2, p3);
    line(p2, p3, p2, p2);
    line(p2, p2, p3, p2);
    line(p3, p2, p3, p3);
  }
}

the output i get:

proc2-output1

So stage shows up, box gets drawn, everything fine.

The problem i have is: i can't get video working. I added the following files to my classpath:

proc2-classpath

(a full text list you can see here: pastebin.com/kTqzL1vW)

but the Video doesn't get displayed. The code i use works fine with the Processing IDE so i guess i just forgot to add something to the classpath or to add additional VM parameters so that the native libs can be found (my guess).

i also tryed to add the following VM parameter to my RUN configuration:

-Djava.library.path=C:/path/to/native/libs

still, all i see is a black screen, no video playing, no exceptions or log output displayed :(

Here is my sample code i use for the Video sample:

import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import processing.video.*;

import java.io.File;

public class Simple extends PApplet
{

public processing.video.Movie myMovie;

public void setup()
{
  size(300, 200);
  background(0);

  // load movie for first window
  final File movieFile = new File("./data/blue-HD.mp4");
  myMovie = new Movie(this, movieFile.getAbsolutePath());
  myMovie.loop();

  if (!movieFile.exists()) System.out.println("movie file NOT found.");
}

public void draw()
{
   image(myMovie, 0, 0);
}

// Called every time a new frame is available to read
void movieEvent(Movie m)
{
  m.read();
  System.out.println("read");
}

}

Can you help me?

Just to show really everything, here is my RUN Configuration:

proc2-runconfig

Answers

  • Ok, i got it working after looking through tons of source code this afternoon. In the example above i did a mistake. i created the method movieEvent(Movie m) without the public access specifier which makes it "protected" per default and than the Movie class can't invoke the method and thus can't load the video frames.

    The correct method should look like:

    // Called every time a new frame is available to read
    public void movieEvent(Movie m)
    {
      m.read();
    }
    

    you see the word "public" in fron of void? that did the trick (shame on me).

    there are nor special VM parameters required but if you run into trouble with the GStreamer native libs (which is the video lib that is used behind the scenes in Processing 2.2.1) add the following:

    -Djna.library.path="C:/GStreamer/libs;C:/GStreamer Test/libs/plugins"
    -Dgstreamer.library.path="C:/GStreamer/libs"
    -Dgstreamer.plugin.path="C:/GStreamer/libs/plugins"
    

    where the directory "GStreamer/libs" should contain all files as listed here pastebin.com/kTqzL1vW (the .jar files arent required but they need to be on your classpath so just put everything at one place)

    HTH, chris

  • Processing's pre-processor stamps the access level keyword public in almost anything automatically!
    When using another IDE, we gotta put those for ourselves! :-S

  • How did you managed to get Processing work with IntelliJ IDEA? I want that too, if you don't mind telling me.

  • @Flu: there is a slide share presentation online that explains how to use processing with IntelliJ IDEA.

    slideshare.net/eskimoblood/processing-in-intellij

    it's for Mac Users but if you have IDEA experience it should be no problem to do the steps on windows also.

    Also there is a book which explains to do it:

    Processing 2: Creative Programming Cookbook

    Chapter 11: Using Processing with Other Editors -> Using Processing with IntelliJ IDEA p.277

    If you have troubles to get it running drop a message here and i'm gonna create a better explanation.

    HTH, chris

  • Thank you, I will try!

  • Yeah, I did it. At first, I couldn't find the Global Libraries stuff but I found it finally. And now, I imported the Processing core and it works. But it annoys me that when the program is run, the applet's window looks like this:

  • It should have been an image there, but for an unknown reason, I can't put it...anyway, the applet's window has like a taskbar up with an Applet menu and down it is like a notification that says Applet started. How I get rid of those?

  • have you looked in preferences and properties?

  • Where do I find those?

  • in the menus

    ;-)

    just kidding

  • But @chris1779 managed to do it somehow.

  • edited July 2014

    @Flu:

    Can you upload a screenshot and show me the window you got?

    for example here 666kb.com/

    or here postimage.org/

    or on any other image sharing site.

  • @Flu

    thats the normal Windows 8 window border that get's added to an applet. In my screenshot above the border is also there. it just looks different.

    to get rid of this border you can change your setup method to look like that:

       public void setup()
       {
         size(800, 600);
         background(0);
    
         frame.dispose();
         frame.setUndecorated(true);
         frame.setVisible(true);
       }
    

    of course thats just one way to do it.

    HTH, chris

  • FluFlu
    edited July 2014

    No, I'm not talking about the bar with the title and the close, minimize, etc. buttons. I am talking about that bar under it, with Applet written on it. In PDE it doesn't put that at all. I know how it looks like the normal windows 8 border. And if I recall corectly, you can take it with:

    void setup() {
      size(200,200);
      frame.removeNotify();
      frame.setUndecorated(true);
    }
    

    What you gave me throws a NullPointerException, but I really don't know why...

  • edited July 2014

    Since I only use Processing's IDE dunno whether this technique can make any diff...
    My idea is having our own main() and invoke PApplet.main() from there:

    static final void main(final String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      PApplet.main(append(args, sketch));
    }
    
  • You know what's weird? My code throws NPE too :-? that is kind of weird since it works perfectly on PDE. @GoToLoop , I don't think your code makes any difference...

  • @Flu

    show me the full stacktrace and your full code, maybe i can help you.

  • FluFlu
    edited July 2014

    @GoToLoop Actually, it gets me an error: Error:(7, 23) java: main(java.lang.String[]) in notesStuff cannot override main(java.lang.String[]) in processing.core.PApplet attempting to assign weaker access privileges; was public

  • @chris1779 What do you mean, stacktrace? What is that? Plus, that's the whole code I gave you earlier:

    import processing.core.PApplet;
    
    public class notesStuff extends PApplet {
    
        public void setup() {
            size(400,400);
    
            line(20,20,80,80);
        }
    }
    
  • Have you actually test it? Anyways, if you just wanna change the text at the title bar, use frame.setTitle("");.

  • edited July 2014

    the code to startup -has too look like that- could look like that:

    static public void main(String[] passedArgs)
      {
        String[] appletArgs = new String[]{"demo.Simple"};
        if (passedArgs != null)
        {
          PApplet.main(concat(appletArgs, passedArgs));
        }
        else
        {
          PApplet.main(appletArgs);
        }
      }
    

    your exception says that you didnt use the word "public" in front of the signature of the main method.

  • ... attempting to assign weaker access privileges; was public

    As any code coming from Processing's IDE, you gotta add public for yourself! (~~)

  • The code to startup has too look like that:

    That's obviously wrong! [-( How would you explain my snippet working too? :>

  • Neither @GoToLoop code or @chris1779 code doeesn't make a difference. I tried them all.

  • @GoToLoop:

    sorry, i'am not native english speakin so i may have accidentally enforced it too much ;)

  • I think the majority of us aren't native english speakers, hmmm... that's weird!

  • edited July 2014

    @Flu

    i think your RUN configuration maybe wrong. Did you create an 'Applet' or an 'Application' RUN configuration?

    Try to create an 'Application' RUN configuration, your should not see a border anymore.

    btw.

    frame.dispose();
    frame.setUndecorated(true);
    frame.setVisible(true);
    

    works for sure (Java8,Processing.2.2.1 :)

    f.666kb.com/i/cps4c7b4q7naillxz.jpg

  • Me neither! But for programming things, where almost everything is possible, the word "should" is more appropriate! O:-)

  • @GoToLoop

    thanks for the hint :)

  • Very well said, @GoToLoop! @chris1779 I think I made an Applet RUN Configuration... but I don't know for sure how do I choose what.

  • @Flu

    To create a RUN configuration select from the menu bar:

    Run -> Edit Configurations ...

    as shown here:

    f.666kb.com/i/cps4hgu1mgoi4oxnb.jpg

    and than click on the + - sign or (Alt+Insert) and select "Application" from the drop down menu. as shown here:

    f.666kb.com/i/cps4iw5e9mc650313.jpg

    of course you also have to select your main class afterwards.

  • edited July 2014

    I've found an example using setUndecorated() here: =:)
    You gotta adapt it to your IDE though! :-SS

    /** 
     * setUndecorated (v4.41)
     * by  rbrauer (2013/Jul)
     * mod GoToLoop (2013/Dec)
     * 
     * forum.processing.org/one/topic/
     * setundecorated-conflic-with-loadlont
     *
     * forum.processing.org/two/discussion/2018/
     * remove-decoration-window-under-p3d
     */
    
    void setup() {
      size(400, 320, removeFrameBorder(P3D));
    
      frameRate(60);
      smooth(8);
      stroke(#00FFFF);
      strokeWeight(1.5);
      textSize(32);
    }
    
    void draw() {
      background(0300);
    
      fill(#FF0000);
      text(frameCount, width - 100, 40);
    
      fill(#0000FF);
      translate(frameCount % width, height >> 1);
      sphere(0150);
    }
    
    String removeFrameBorder(String gfx) {
      if (!isGL()) {
        frame.removeNotify();
        frame.setUndecorated(true);
        frame.addNotify();
      }
    
      return gfx;
    }
    
  • I think I will stick with the PDE :)

Sign In or Register to comment.