Page 1 of 1

LibVLC for Android - JNI Error

Posted: 22 Sep 2014 19:07
by liutingdu
Hi,

I am working on an Android application that embedded LibVLC to play RTSP streams.

I compiled LibVLC for Android(version 0.9.9) and imported the compiled code into my Android project.

I am following this samplehttps://bitbucket.org/edwardcw/libvlc-a ... ?at=master

The main codes are :

Code: Select all

// Create a new media player libvlc = LibVLC.getInstance(); libvlc.setHardwareAcceleration(LibVLC.HW_ACCELERATION_DISABLED); libvlc.setSubtitlesEncoding(""); libvlc.setAout(LibVLC.AOUT_OPENSLES); libvlc.setTimeStretching(true); libvlc.setChroma("RV32"); libvlc.setVerboseMode(true); LibVLC.restart(this); EventHandler.getInstance().addHandler(mHandler); holder.setFormat(PixelFormat.RGBX_8888); holder.setKeepScreenOn(true); MediaList list = libvlc.getMediaList(); list.clear(); list.add(new Media(libvlc, LibVLC.PathToURI(media)), false); libvlc.playIndex(0);
It works well with playing the single URL once.

But if I return to the previous activity and attempt to play it again, it will crash at this line:

Code: Select all

LibVLC.restart(this);
And the error showing in LogCat is: 'JNI ERROR (app bug): attempt to use stale local reference'

After researching about this, it actually crashes at ''destroy_native_crash_handler()' in 'native_crash_handler.c'. It's a very similar issue with https://code.google.com/p/dolphin-playe ... tail?id=19

Then did a temporary fix: deleted this line: '(*env)->DeleteGlobalRef(env, j_libVLC);' from 'native_crash_handler.c', recompiled it and import the recompiled native code into my project, the crash is gone.

But I am afraid that the way I fixed it will cause other problems because I am new to JNI and know nothing about LibVLC.

Is it possible that it's a bug? Or maybe I am not using 'LibVLC.java' in the proper way but I couldn't find any other samples around usage of this class.

Any help in this matter would be highly appreciated.

Thanks a lot!
Liuting

Re: LibVLC for Android - JNI Error

Posted: 22 Sep 2014 21:04
by tylerjroach
I was able to stop this same crash by removing these two lines from the releasePlayer() method.

libvlc.destroy();
libvlc = null;

Re: LibVLC for Android - JNI Error

Posted: 23 Sep 2014 10:51
by liutingdu
I was able to stop this same crash by removing these two lines from the releasePlayer() method.

libvlc.destroy();
libvlc = null;
Thanks it's working!