]> git.sesse.net Git - vlc/blob - bindings/java/src/playlist-jni.cc
2f8d4bb4645a563b2544408838b711a9ad651990
[vlc] / bindings / java / src / playlist-jni.cc
1 /*****************************************************************************\r
2  * playlist-jni.cc: JNI native playlist functions for VLC Java Bindings\r
3  *****************************************************************************\r
4  * Copyright (C) 1998-2006 the VideoLAN team\r
5  *\r
6  * Authors: Filippo Carone <filippo@carone.org>\r
7  *\r
8  *\r
9  * $Id $\r
10  *\r
11  * This program is free software; you can redistribute it and/or modify\r
12  * it under the terms of the GNU General Public License as published by\r
13  * the Free Software Foundation; either version 2 of the License, or\r
14  * (at your option) any later version.\r
15  *\r
16  * This program is distributed in the hope that it will be useful,\r
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
19  * GNU General Public License for more details.\r
20  *\r
21  * You should have received a copy of the GNU General Public License\r
22  * along with this program; if not, write to the Free Software\r
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.\r
24  *****************************************************************************/\r
25 \r
26 /* These are a must*/\r
27 #include <jni.h>\r
28 #include <vlc/libvlc.h>\r
29 #ifdef WIN32\r
30 #include <windows.h>\r
31 #undef usleep\r
32 #define usleep(var) Sleep(var/1000)\r
33 #else\r
34 #include <unistd.h>\r
35 #endif\r
36 #include <stdio.h>\r
37 \r
38 /* JVLC internal imports, generated by gcjh */\r
39 #include "../includes/Playlist.h"\r
40 \r
41 #include "utils.h"\r
42 \r
43 \r
44 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1playlist_1add (JNIEnv *env, jobject _this, jstring uri, jstring name,  jobjectArray options) {\r
45 \r
46     INIT_FUNCTION ;\r
47     \r
48     int res = 0;\r
49     int i_options = 0;\r
50     const char** ppsz_options = NULL;\r
51     const char* psz_uri  = env->GetStringUTFChars( uri, 0 );\r
52     const char* psz_name = env->GetStringUTFChars( name, 0 );\r
53 \r
54     if ( options != NULL ) {\r
55         i_options = ( int ) env->GetArrayLength( ( jarray ) options ) + 1;\r
56         ppsz_options = ( const char ** ) malloc( i_options * sizeof( char* ) );\r
57         sprintf( ( char * ) ppsz_options[0], "%s", "jvlc" );\r
58 \r
59         for (int i = 0; i < i_options - 1; i++) {\r
60             ppsz_options[ i+1 ] =\r
61                 env->GetStringUTFChars( ( jstring ) env->GetObjectArrayElement( options, i ), 0 );\r
62         }\r
63         res = libvlc_playlist_add_extended( ( libvlc_instance_t * ) instance, psz_uri, psz_name, i_options, ppsz_options, &exception );\r
64 \r
65         CHECK_EXCEPTION;\r
66         \r
67     } else {\r
68         res = libvlc_playlist_add( ( libvlc_instance_t * ) instance, psz_uri, psz_name, &exception );\r
69         \r
70         CHECK_EXCEPTION;\r
71     }\r
72     \r
73     if (psz_uri != NULL) {\r
74         env->ReleaseStringUTFChars( uri, psz_uri );\r
75     }\r
76 \r
77     if (psz_name != NULL) {\r
78         env->ReleaseStringUTFChars( name, psz_name );\r
79     }\r
80 \r
81     return res;\r
82 }\r
83 \r
84 \r
85 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1play (JNIEnv *env, jobject _this, jint id, jobjectArray options)\r
86 {\r
87 \r
88     INIT_FUNCTION;\r
89     \r
90     int i_options = 0;\r
91     const char** ppsz_options = NULL;\r
92 \r
93     if ( options != NULL ) {\r
94        i_options = ( int ) env->GetArrayLength( ( jarray ) options );\r
95        ppsz_options = ( const char ** ) malloc( i_options * sizeof( char* ) );\r
96        for ( int i = 0; i < i_options - 1; i++ ) {\r
97            ppsz_options[ i ] = \r
98                env->GetStringUTFChars( ( jstring ) env->GetObjectArrayElement( options, i ), 0 );\r
99        }\r
100     }\r
101 \r
102     libvlc_playlist_play( ( libvlc_instance_t * ) instance, id, i_options, ( char **  ) ppsz_options, &exception );\r
103 \r
104     CHECK_EXCEPTION;\r
105     \r
106     while (! libvlc_playlist_isplaying( (libvlc_instance_t*) instance, &exception ) )\r
107     {\r
108         usleep(100);\r
109     }\r
110 \r
111     CHECK_EXCEPTION;\r
112 }\r
113 \r
114 \r
115 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1pause (JNIEnv *env, jobject _this)\r
116 {\r
117     INIT_FUNCTION ;\r
118 \r
119     libvlc_playlist_pause( ( libvlc_instance_t* ) instance, &exception );\r
120 \r
121     CHECK_EXCEPTION ;\r
122 }\r
123 \r
124 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1stop (JNIEnv *env, jobject _this)\r
125 {\r
126     INIT_FUNCTION ;\r
127 \r
128     libvlc_playlist_stop( ( libvlc_instance_t* ) instance, &exception );\r
129     \r
130     while ( libvlc_playlist_isplaying( (libvlc_instance_t*) instance, &exception ) )\r
131     {\r
132         usleep(100);\r
133     }\r
134     \r
135 \r
136     CHECK_EXCEPTION ;\r
137 }\r
138 \r
139 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1next (JNIEnv *env, jobject _this)\r
140 {\r
141     INIT_FUNCTION ;\r
142     \r
143     libvlc_playlist_next( ( libvlc_instance_t* ) instance, &exception );\r
144 \r
145     CHECK_EXCEPTION ;\r
146 }\r
147 \r
148 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1prev (JNIEnv *env, jobject _this)\r
149 {\r
150     INIT_FUNCTION ;\r
151     \r
152     libvlc_playlist_prev( (libvlc_instance_t*) instance, &exception );\r
153 \r
154     CHECK_EXCEPTION ;\r
155 }\r
156 \r
157 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1clear (JNIEnv *env, jobject _this)\r
158 {\r
159     INIT_FUNCTION ;\r
160 \r
161     libvlc_playlist_clear( (libvlc_instance_t*) instance, &exception );\r
162 \r
163     CHECK_EXCEPTION ;\r
164 }\r
165 \r
166 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1deleteItem (JNIEnv *env, jobject _this, jint itemID)\r
167 {\r
168     INIT_FUNCTION ;\r
169 \r
170     libvlc_playlist_delete_item( ( libvlc_instance_t * ) instance, itemID, &exception );\r
171 \r
172     CHECK_EXCEPTION ;\r
173 }\r
174 \r
175 \r
176 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1itemsCount (JNIEnv *env, jobject _this)\r
177 {\r
178     INIT_FUNCTION ;\r
179     int res = 0;\r
180 \r
181     res = libvlc_playlist_items_count( (libvlc_instance_t*) instance, &exception );\r
182 \r
183     CHECK_EXCEPTION ;\r
184 \r
185     return res;\r
186 \r
187 }\r
188 \r
189 JNIEXPORT jint JNICALL Java_org_videolan_jvlc_Playlist__1isRunning (JNIEnv *env, jobject _this)\r
190 {\r
191     INIT_FUNCTION ;\r
192     int res = 0;\r
193 \r
194     res = libvlc_playlist_isplaying( (libvlc_instance_t*) instance, &exception );\r
195 \r
196     CHECK_EXCEPTION ;\r
197 \r
198     return res;\r
199 }\r
200 \r
201 JNIEXPORT void JNICALL Java_org_videolan_jvlc_Playlist__1setLoop\r
202   (JNIEnv *env, jobject _this, jboolean loop)\r
203 {\r
204    INIT_FUNCTION ;\r
205 \r
206    libvlc_playlist_loop( (libvlc_instance_t*) instance, loop, &exception );\r
207 \r
208    CHECK_EXCEPTION ;\r
209    \r
210 }   \r