Commit 21e3fded authored by Thomas Guillem's avatar Thomas Guillem

android: get JavaVM* from JNI_OnLoad

And set the JavaVM* in a libvlc var option.

This will allow android modules to access a JNIEnv* even when the parent is a
not a libvlc_media_player. This will be used for the android Keystore module
for example.

Furthermore, this simplify the libvlc API when setting an android context.
parent e97065eb
......@@ -548,13 +548,11 @@ LIBVLC_API void *libvlc_media_player_get_hwnd ( libvlc_media_player_t *p_mi );
* \version LibVLC 3.0.0 and later.
* \param p_mi the media player
* \param p_jvm the Java VM of the android process.
* \param p_awindow_handler org.videolan.libvlc.IAWindowNativeHandler jobject
* implemented by the org.videolan.libvlc.MediaPlayer class from the
* libvlc-android project.
LIBVLC_API void libvlc_media_player_set_android_context( libvlc_media_player_t *p_mi,
void *p_jvm,
void *p_awindow_handler );
......@@ -593,7 +593,6 @@ libvlc_media_player_new( libvlc_instance_t *instance )
var_Create (mp, "drawable-nsobject", VLC_VAR_ADDRESS);
#ifdef __ANDROID__
var_Create (mp, "android-jvm", VLC_VAR_ADDRESS);
var_Create (mp, "drawable-androidwindow", VLC_VAR_ADDRESS);
#ifdef HAVE_EVAS
......@@ -1172,15 +1171,13 @@ void *libvlc_media_player_get_hwnd( libvlc_media_player_t *p_mi )
* set_android_context
void libvlc_media_player_set_android_context( libvlc_media_player_t *p_mi,
void *p_jvm,
void *p_awindow_handler )
assert (p_mi != NULL);
#ifdef __ANDROID__
var_SetAddress (p_mi, "android-jvm", p_jvm);
var_SetAddress (p_mi, "drawable-androidwindow", p_awindow_handler);
(void) p_jvm; (void) p_awindow_handler;
(void) p_awindow_handler;
libvlc_printerr ("can't set android context: ANDROID build required");
var_SetString (p_mi, "vout", "none");
......@@ -269,7 +269,7 @@ SOURCES_libvlc_android = \
posix/timer.c \
posix/linux_cpu.c \
posix/linux_specific.c \
posix/specific.c \
android/specific.c \
posix/rand.c \
* specific.c: stubs for Android OS-specific initialization
* Copyright © 2016 VLC authors and VideoLAN
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
# include "config.h"
#include <assert.h>
#include <vlc_common.h>
#include "../libvlc.h"
#include <jni.h>
static JavaVM *s_jvm = NULL;
/* This function is called when the libvlcore dynamic library is loaded via the
* java.lang.System.loadLibrary method. Therefore, s_jvm will be already set
* when libvlc_InternalInit is called. */
JNI_OnLoad(JavaVM *vm, void *reserved)
(void) reserved;
s_jvm = vm;
return JNI_VERSION_1_2;
JNI_OnUnload(JavaVM* vm, void* reserved)
(void) vm;
(void) reserved;
system_Configure(libvlc_int_t *p_libvlc, int i_argc, const char *const pp_argv[])
(void)i_argc; (void)pp_argv;
assert(s_jvm != NULL);
var_Create(p_libvlc, "android-jvm", VLC_VAR_ADDRESS);
var_SetAddress(p_libvlc, "android-jvm", s_jvm);
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