NullPointerException on MovieCreator().build android unity plugin

817 Views Asked by At

I am using mp4parser in my app to merge audio and video which is working fine in android. But when I make .aar file and add the plugin in unity it throws a NullPointerException.

Here is the log

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.coremedia.iso.PropertyBoxParserImpl.(PropertyBoxParserImpl.java:67) 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.coremedia.iso.IsoFile.(IsoFile.java:59) 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:49) 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.googlecode.mp4parser.authoring.container.mp4.MovieCreator.build(MovieCreator.java:38) 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.actvt.showdown.pluggin.Mp4ParserAudioMuxer.mux(Mp4ParserAudioMuxer.java:31)
 12-20 13:47:07.409 9171-10512/? W/System.err: at com.actvt.showdown.pluggin.Utils.mergeAudioAndVideo(Utils.java:217) 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.actvt.showdown.pluggin.Utils.access$400(Utils.java:44) 
12-20 13:47:07.409 9171-10512/? W/System.err: at com.actvt.showdown.pluggin.Utils$1.run(Utils.java:200) 
12-20 13:47:07.410 9171-10512/? W/System.err: at java.lang.Thread.run(Thread.java:761)

When I do

video = new MovieCreator().build(videoFile);

It is not finding a isoparser-default.properties file in the jar or something like that? I'm using this jar to use mp4 parser in unity3d pluggin android native code.

1

There are 1 best solutions below

3
On

I'm currently having the same issue, although I do not have a solution I do know the cause of this bug, in PropertyBoxParserImpl.java it is trying to fetch this file:

InputStream is = getClass().getResourceAsStream("/isoparser-default.properties");

And it is not finding isoparser-default.properties although it is packaged in the .jar/.aar file in Unity, I believe the solution is to find a way to get that file to load with Unity.

EDIT:

I've figured it out, and will post as an ISSUE on the mp4parser git repo, here's what I did:

I've created copies of these classes:

  • IsoFile
  • MovieCreator
  • PropertyBoxParserImpl

In PropertyBoxParserImpl class, I've modified this line:

InputStream is = getClass().getResourceAsStream("/isoparser-default.properties");

into this line:

InputStream is = UnityPlayer.currentActivity.getApplicationContext().getAssets().open("isoparser-default.properties");

I've also placed the isoparser-default.properties inside my src/assets folder in the Android Studio project so now it loaded up the file without any errors.

Next step was taking the aspectjrt.jar file from the external libraries and putting it inside the Plugins/Android folder in the Unity project, same thing for the mp4parser jar file.

Once all of that was done I was able to combine mp4 files from Unity, remember that if both files do not have the same encoding/bitrate/resolution the merge will fail.

EDIT #2:

Actually, I'm sorry but that still doesn't find the file, you actually need to rewrite the file in the Unity applications data folder on the mobile device, I've done this using the WWW class in Unity, and copied the file to Application.persistentDataPath + "/isoparser-defaut.properties"

Hope that helps!