Commit 4f6f5e01 authored by Thomas Guillem's avatar Thomas Guillem

LibVLC: setup HOME env variable from an Android Context

parent 21603a2a
...@@ -356,7 +356,9 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) ...@@ -356,7 +356,9 @@ void JNI_OnUnload(JavaVM* vm, void* reserved)
#endif #endif
} }
void Java_org_videolan_libvlc_LibVLC_nativeNew(JNIEnv *env, jobject thiz, jobjectArray jstringArray) void Java_org_videolan_libvlc_LibVLC_nativeNew(JNIEnv *env, jobject thiz,
jobjectArray jstringArray,
jstring jhomePath)
{ {
vlcjni_object *p_obj = NULL; vlcjni_object *p_obj = NULL;
libvlc_instance_t *p_libvlc = NULL; libvlc_instance_t *p_libvlc = NULL;
...@@ -364,6 +366,16 @@ void Java_org_videolan_libvlc_LibVLC_nativeNew(JNIEnv *env, jobject thiz, jobjec ...@@ -364,6 +366,16 @@ void Java_org_videolan_libvlc_LibVLC_nativeNew(JNIEnv *env, jobject thiz, jobjec
const char **argv = NULL; const char **argv = NULL;
int argc = 0; int argc = 0;
if (jhomePath)
{
const char *psz_home = (*env)->GetStringUTFChars(env, jhomePath, 0);
if (psz_home)
{
setenv("HOME", psz_home, 1);
(*env)->ReleaseStringUTFChars(env, jhomePath, psz_home);
}
}
if (jstringArray) if (jstringArray)
{ {
argc = (*env)->GetArrayLength(env, jstringArray); argc = (*env)->GetArrayLength(env, jstringArray);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
package org.videolan.libvlc; package org.videolan.libvlc;
import android.content.Context;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
...@@ -45,7 +46,7 @@ public class LibVLC extends VLCObject<LibVLC.Event> { ...@@ -45,7 +46,7 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
* *
* @param options * @param options
*/ */
public LibVLC(ArrayList<String> options) { public LibVLC(Context context, ArrayList<String> options) {
loadLibraries(); loadLibraries();
boolean setAout = true, setChroma = true; boolean setAout = true, setChroma = true;
...@@ -78,14 +79,14 @@ public class LibVLC extends VLCObject<LibVLC.Event> { ...@@ -78,14 +79,14 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
} }
} }
nativeNew(options.toArray(new String[options.size()])); nativeNew(options.toArray(new String[options.size()]), context.getDir("vlc", Context.MODE_PRIVATE).getAbsolutePath());
} }
/** /**
* Create a LibVLC * Create a LibVLC
*/ */
public LibVLC() { public LibVLC(Context context) {
this(null); this(context, null);
} }
/** /**
...@@ -141,10 +142,10 @@ public class LibVLC extends VLCObject<LibVLC.Event> { ...@@ -141,10 +142,10 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
} }
/* JNI */ /* JNI */
private native void nativeNew(String[] options); private native void nativeNew(String[] options, String homePath);
private native void nativeRelease(); private native void nativeRelease();
private native void nativeSetUserAgent(String name, String http); private native void nativeSetUserAgent(String name, String http);
private static boolean sLoaded = false; private static boolean sLoaded = false;
static synchronized void loadLibraries() { static synchronized void loadLibraries() {
......
...@@ -72,7 +72,7 @@ public class MediaPlayer ...@@ -72,7 +72,7 @@ public class MediaPlayer
private org.videolan.libvlc.MediaPlayer mMediaPlayer; private org.videolan.libvlc.MediaPlayer mMediaPlayer;
public MediaPlayer() { public MediaPlayer() {
mLibVLC = new LibVLC(); //FIXME, this is wrong mLibVLC = new LibVLC(null); //FIXME, this is wrong
mMediaPlayer = new org.videolan.libvlc.MediaPlayer(mLibVLC); mMediaPlayer = new org.videolan.libvlc.MediaPlayer(mLibVLC);
} }
......
...@@ -55,6 +55,7 @@ public class VideoView extends SurfaceView ...@@ -55,6 +55,7 @@ public class VideoView extends SurfaceView
public VideoView(Context context) { public VideoView(Context context) {
super(context); super(context);
sLibVLC = new LibVLC(context, null);
} }
public VideoView(Context context, AttributeSet attrs) { public VideoView(Context context, AttributeSet attrs) {
...@@ -70,10 +71,6 @@ public class VideoView extends SurfaceView ...@@ -70,10 +71,6 @@ public class VideoView extends SurfaceView
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
private void initLibVLC() {
sLibVLC = new LibVLC();
}
@Override @Override
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void onInitializeAccessibilityEvent(AccessibilityEvent event) { public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
...@@ -91,12 +88,10 @@ public class VideoView extends SurfaceView ...@@ -91,12 +88,10 @@ public class VideoView extends SurfaceView
} }
public void setVideoPath(String path) { public void setVideoPath(String path) {
initLibVLC();
final Media media = new Media(sLibVLC, path); final Media media = new Media(sLibVLC, path);
} }
public void setVideoURI(Uri uri) { public void setVideoURI(Uri uri) {
initLibVLC();
final Media media = new Media(sLibVLC, uri); final Media media = new Media(sLibVLC, uri);
} }
......
...@@ -60,7 +60,7 @@ public class Dumper { ...@@ -60,7 +60,7 @@ public class Dumper {
options.add("--no-audio"); options.add("--no-audio");
options.add("--no-spu"); options.add("--no-spu");
options.add("-vvv"); options.add("-vvv");
mLibVLC = new LibVLC(options); mLibVLC = new LibVLC(null, options);
final Media media = new Media(mLibVLC, uri); final Media media = new Media(mLibVLC, uri);
mMediaPlayer = new MediaPlayer(media); mMediaPlayer = new MediaPlayer(media);
......
...@@ -111,7 +111,7 @@ public class VLCInstance { ...@@ -111,7 +111,7 @@ public class VLCInstance {
linkCompatLib(context); linkCompatLib(context);
} }
sLibVLC = new LibVLC(VLCOptions.getLibOptions()); sLibVLC = new LibVLC(context, VLCOptions.getLibOptions());
LibVLC.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() { LibVLC.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() {
@Override @Override
public void onNativeCrash() { public void onNativeCrash() {
...@@ -130,7 +130,7 @@ public class VLCInstance { ...@@ -130,7 +130,7 @@ public class VLCInstance {
public static synchronized void restart() throws IllegalStateException { public static synchronized void restart() throws IllegalStateException {
if (sLibVLC != null) { if (sLibVLC != null) {
sLibVLC.release(); sLibVLC.release();
sLibVLC = new LibVLC(VLCOptions.getLibOptions()); sLibVLC = new LibVLC(VLCApplication.getAppContext(), VLCOptions.getLibOptions());
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment