I'm trying to run a movie using the Processing 2.0 Movie class.
If I run my program from my code editor (Eclipse in my case) everything works fine and the code runs flawlessly: it locates and starts the movie.
However, when I export my program to a jar and start it from my terminal, it does locate the file but it crashes on trying to open it.
I am currently using this code to find my movie path string.
public String locateMovie(String moviePath) {
String movie = MoviePlayer.class.getClassLoader().getResource(moviePath).getPath();
if (movie == null) {
System.out.println("FATAL ERROR --- Movie file not found: '" + moviePath + "'");
}
return movie;
}
As you can see I am using the classLoader to locate the file for me since the paths are different after I export it to a .jar file and do not wish to change the paths all the time myself. The .getPath() deletes the 'File:' in File:/Path/To/My/File as this is an unneeded side effect from using the above way.
A bit further in my code I've already added an extra check to see if nothing is wrong with the path that the classLoader is returning, I do this with the following lines.
File temp = new File(moviePath);
System.out.println("If I have something after this, the file exists: '" + temp + "'");
It always returns the right path, whether it's running from within my Eclipse (/Users/Path/To/My/Folder/2/java/Game/movies/introMovie.mp4) or from the executable .jar file (introMovie.mp4).
At first I thought it was strange that in the .jar file it was giving me a file straight away without the path leading to it because it does have some structure in my project but after using the
jar tf myProject.jar
command in my commandLine it returns the same file/pathname for the file so the path should be correct and all is still well here.
But now, when I try to load the movie via Processing' Movie class with the following code:
currentMovie = new Movie(parent, moviePath);
It throws an java.lang.StringIndexOutOfBoundsException exception and crashes. I have no idea what i'm doing wrong since this code runs flawlessly from within my code editor + I'm using the same way of locating files for my audio files and those run aswel, even from the executable .jar file.
As far as I can tell from reading the Movie class reference library it just needs a place to display it on and the path to the file which I am both giving.
I was hoping some veteran here could see what I am doing wrong and help me solve this problem that I'm been struggling with for a few days now. It's probably something stupid that I'm just overlooking right now.