]> git.sesse.net Git - vlc/blob - bindings/java/src/callback-jni.cc
the object pointer is null in the handler, so use null here
[vlc] / bindings / java / src / callback-jni.cc
1 /*****************************************************************************
2  * callback-jni.cc: JNI native callback functions for VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2006 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  *
9  * $Id $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /* These are a must*/
27 #include <jni.h>
28 #include <vlc/libvlc.h>
29 #ifdef WIN32
30 #include <windows.h>
31 #undef usleep
32 #define usleep(var) Sleep(var/1000)
33 #else
34 #include <unistd.h>
35 #endif
36 #include <stdio.h>
37
38 #include "utils.h"
39
40 #include "../includes/Audio.h"
41
42 static JavaVM *jvm;
43 static jclass audioClass;
44 static jmethodID wakeupListenersMethod;
45
46 void volumeChangedCallback( libvlc_instance_t *p_instance, libvlc_event_t *event, void *user_data );
47
48
49 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Audio__1install_1callback( JNIEnv *env, jobject _this )
50 {
51     INIT_FUNCTION ;
52     if (jvm == NULL)
53     {
54         env->GetJavaVM( &jvm );
55         audioClass = env->GetObjectClass( _this );
56         wakeupListenersMethod = env->GetStaticMethodID(audioClass, "wakeupListeners", "()V");
57     }
58
59     libvlc_callback_register_for_event( ( libvlc_instance_t* ) instance,
60                                         VOLUME_CHANGED,
61                                         volumeChangedCallback,
62                                         NULL,
63                                         exception );
64     CHECK_EXCEPTION_FREE ;
65 }
66
67 void volumeChangedCallback( struct libvlc_instance_t *p_instance, libvlc_event_t *event, void *user_data )
68 {
69     JNIEnv *env;
70     jvm->AttachCurrentThread( ( void ** ) &env, NULL );
71
72     env->CallStaticVoidMethod( audioClass, wakeupListenersMethod);
73 }