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)
#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;
libvlc_instance_t *p_libvlc = NULL;
......@@ -364,6 +366,16 @@ void Java_org_videolan_libvlc_LibVLC_nativeNew(JNIEnv *env, jobject thiz, jobjec
const char **argv = NULL;
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)
{
argc = (*env)->GetArrayLength(env, jstringArray);
......
......@@ -20,6 +20,7 @@
package org.videolan.libvlc;
import android.content.Context;
import android.os.Build;
import android.util.Log;
......@@ -45,7 +46,7 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
*
* @param options
*/
public LibVLC(ArrayList<String> options) {
public LibVLC(Context context, ArrayList<String> options) {
loadLibraries();
boolean setAout = true, setChroma = true;
......@@ -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
*/
public LibVLC() {
this(null);
public LibVLC(Context context) {
this(context, null);
}
/**
......@@ -141,7 +142,7 @@ public class LibVLC extends VLCObject<LibVLC.Event> {
}
/* JNI */
private native void nativeNew(String[] options);
private native void nativeNew(String[] options, String homePath);
private native void nativeRelease();
private native void nativeSetUserAgent(String name, String http);
......
......@@ -72,7 +72,7 @@ public class MediaPlayer
private org.videolan.libvlc.MediaPlayer mMediaPlayer;
public MediaPlayer() {
mLibVLC = new LibVLC(); //FIXME, this is wrong
mLibVLC = new LibVLC(null); //FIXME, this is wrong
mMediaPlayer = new org.videolan.libvlc.MediaPlayer(mLibVLC);
}
......
......@@ -55,6 +55,7 @@ public class VideoView extends SurfaceView
public VideoView(Context context) {
super(context);
sLibVLC = new LibVLC(context, null);
}
public VideoView(Context context, AttributeSet attrs) {
......@@ -70,10 +71,6 @@ public class VideoView extends SurfaceView
super(context, attrs, defStyleAttr, defStyleRes);
}
private void initLibVLC() {
sLibVLC = new LibVLC();
}
@Override
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
......@@ -91,12 +88,10 @@ public class VideoView extends SurfaceView
}
public void setVideoPath(String path) {
initLibVLC();
final Media media = new Media(sLibVLC, path);
}
public void setVideoURI(Uri uri) {
initLibVLC();
final Media media = new Media(sLibVLC, uri);
}
......
......@@ -60,7 +60,7 @@ public class Dumper {
options.add("--no-audio");
options.add("--no-spu");
options.add("-vvv");
mLibVLC = new LibVLC(options);
mLibVLC = new LibVLC(null, options);
final Media media = new Media(mLibVLC, uri);
mMediaPlayer = new MediaPlayer(media);
......
......@@ -111,7 +111,7 @@ public class VLCInstance {
linkCompatLib(context);
}
sLibVLC = new LibVLC(VLCOptions.getLibOptions());
sLibVLC = new LibVLC(context, VLCOptions.getLibOptions());
LibVLC.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() {
@Override
public void onNativeCrash() {
......@@ -130,7 +130,7 @@ public class VLCInstance {
public static synchronized void restart() throws IllegalStateException {
if (sLibVLC != null) {
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