Importing and using processing .jar libraries

321 views
Skip to first unread message

Benjamin McFetridge

unread,
Jun 19, 2012, 1:16:26 AM6/19/12
to pyprocessing-users
Hi,

I was wondering how to import and use some of the libraries that come
with processing specifically the video library (http://processing.org/
reference/libraries/video/index.html) as I have run into difficulties
trying to get it to work.

I have copied the video.jar file which comes with processing and
placed it in a folder named video in the same directory as my .py
file. I can manage to import it without it throwing any errors but
it's not letting me create an instance of a Movie.

This is the example given in the reference for processing of how to
setup a movie (http://processing.org/reference/libraries/video/
Movie.html):

import processing.video.*;
Movie myMovie;

void setup() {
size(200, 200, P2D);
myMovie = new Movie(this, "totoro.mov");
myMovie.loop();
}

This is what I have in pyprocessing, trying to recreate it:

import video

def setup():
size(600, 600, P2D)
m = None
m = Movie(this, "y.mp4") #y.mp4 is my movie file

However it's throwing an error. NameError: global name 'Movie' is not
defined. So I must be doing something wrong, the constructor according
to the reference is as follows:

Movie(parent, filename)

So I'm using the correct convention but I don't think that's what's
causing the error.

Some of the things I have tried:

To create an empty movie and then fill in the fields, but that too
causes the same NameError.
Inserting global Movie at the start of setup() doesn't change
anything either
Neither does moving the code from setup() to draw() or even it's
own function. I can't manage to find anything on Google either that
solves the issue.
Changing the way to import the module instead of using import
video, I tried using from video import * but nothing changed.


I think it has to be something to do with the way I'm trying to
initialise the movie file, but I can't figure it out.

A bit of other info that may be causing the error: I have my movie
clip in the same directory as my .pyp sketch and .mp4 is a compatible
file type as I can get it to run in processing although the audio does
cut out after 2 seconds in processing for some odd reason but not the
issue I'm worried about currently.

Also can you use the keyword this in python to specify the file
location?

Thanks in advance,

Benjamin McFetridge

Claudio Esperança

unread,
Jun 19, 2012, 1:58:02 PM6/19/12
to pyprocess...@googlegroups.com
I think you are under the impression that pyprocessing uses Processing's programming environment. Pyprocessing runs under CPython, i.e., it does not use Java's virtual machine, and thus it cannot import .jar libraries. If you want to load and play sounds and videos from within a Python application, you might try using pyglet's functions. Pyprocessing also uses pyglet for things like fonts and windows...

FlightOfGrey

unread,
Jun 19, 2012, 5:32:54 PM6/19/12
to pyprocess...@googlegroups.com
Ah yes you're right, I hadn't really looked into how pyprocessing ran.

Thanks for the help.

Juego

unread,
Jun 20, 2012, 4:49:21 AM6/20/12
to pyprocess...@googlegroups.com
To use the processing environement with python, there is
https://github.com/jdf/processing.py
Though I haven't tried it.

My 2 cents.

Le 19/06/12 23:32, FlightOfGrey a �crit :
> Ah yes you're right, I hadn't really looked into how pyprocessing ran.
>
> Thanks for the help.
>
> On 20/06/2012 5:58 a.m., Claudio Esperan�a wrote:
>> I think you are under the impression that pyprocessing uses
>> Processing's programming environment. Pyprocessing runs under CPython,
>> i.e., it does not use Java's virtual machine, and thus it cannot
>> import .jar libraries. If you want to load and play sounds and videos
>> from within a Python application, you might try using pyglet's
>> functions. Pyprocessing also uses pyglet for things like fonts and
>> windows...
>>
>>
>> On Tue, Jun 19, 2012 at 2:16 AM, Benjamin McFetridge
>> <flight...@gmail.com <mailto:flight...@gmail.com>> wrote:
>>
>> Hi,
>>
>> I was wondering how to import and use some of the libraries that come
>> with processing specifically the video library (http://processing.org/
>> reference/libraries/video/index.html
>> <http://processing.org/%0Areference/libraries/video/index.html>)
--
blog: http://p.xuv.be
site: http://xuv.be
Reply all
Reply to author
Forward
0 new messages