Commit 600a2926 authored by Thomas Guillem's avatar Thomas Guillem

LibVLC: MediaDiscoverer: add getServices

parent 6f6c553f
......@@ -88,3 +88,57 @@ Java_org_videolan_libvlc_MediaDiscoverer_nativeStop(JNIEnv *env, jobject thiz)
libvlc_media_discoverer_stop(p_obj->u.p_md);
}
static jobject
service_to_object(JNIEnv *env, libvlc_media_discoverer_service *p_service)
{
jstring jname = NULL;
jstring jlongName = NULL;
jname = (*env)->NewStringUTF(env, p_service->psz_name);
jlongName = (*env)->NewStringUTF(env, p_service->psz_longname);
return (*env)->CallStaticObjectMethod(env, fields.MediaDiscoverer.clazz,
fields.MediaDiscoverer.createServiceFromNativeID,
jname, jlongName, p_service->i_cat);
}
jobject
Java_org_videolan_libvlc_MediaDiscoverer_nativeGetServices(JNIEnv *env,
jobject thiz,
jobject libVlc,
jint i_category)
{
vlcjni_object *p_lib_obj = VLCJniObject_getInstance(env, libVlc);
libvlc_instance_t *p_libvlc = p_lib_obj->u.p_libvlc;
libvlc_media_discoverer_service **pp_services = NULL;
unsigned int i_nb_services = 0;
jobjectArray array;
if (!p_lib_obj)
return NULL;
i_nb_services =
libvlc_media_discoverer_services_get( p_libvlc, i_category,
&pp_services);
if (i_nb_services == 0)
return NULL;
array = (*env)->NewObjectArray(env, i_nb_services,
fields.MediaDiscoverer.Service.clazz, NULL);
if (!array)
goto error;
for (int i = 0; i < i_nb_services; ++i)
{
jobject jservice = service_to_object(env, pp_services[i]);
(*env)->SetObjectArrayElement(env, array, i, jservice);
}
error:
if (pp_services)
libvlc_media_discoverer_services_release(pp_services, i_nb_services);
return array;
}
......@@ -186,6 +186,10 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
"org/videolan/libvlc/MediaPlayer$TrackDescription", true);
GET_CLASS(fields.MediaPlayer.Equalizer.clazz,
"org/videolan/libvlc/MediaPlayer$Equalizer", true);
GET_CLASS(fields.MediaDiscoverer.clazz,
"org/videolan/libvlc/MediaDiscoverer", true);
GET_CLASS(fields.MediaDiscoverer.Service.clazz,
"org/videolan/libvlc/MediaDiscoverer$Service", true);
GET_CLASS(fields.Dialog.clazz,
"org/videolan/libvlc/Dialog", true);
......@@ -272,6 +276,13 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
"createTrackDescriptionFromNative",
"(ILjava/lang/String;)Lorg/videolan/libvlc/MediaPlayer$TrackDescription;");
GET_ID(GetStaticMethodID,
fields.MediaDiscoverer.createServiceFromNativeID,
fields.MediaDiscoverer.clazz,
"createServiceFromNative",
"(Ljava/lang/String;Ljava/lang/String;I)"
"Lorg/videolan/libvlc/MediaDiscoverer$Service;");
GET_ID(GetStaticMethodID,
fields.Dialog.displayErrorFromNativeID,
fields.Dialog.clazz,
......
......@@ -82,6 +82,13 @@ struct fields {
jmethodID createChapterFromNativeID;
jmethodID createTrackDescriptionFromNativeID;
} MediaPlayer;
struct {
struct {
jclass clazz;
} Service;
jclass clazz;
jmethodID createServiceFromNativeID;
} MediaDiscoverer;
struct {
jclass clazz;
jmethodID displayErrorFromNativeID;
......
......@@ -20,6 +20,8 @@
package org.videolan.libvlc;
import android.support.annotation.Nullable;
@SuppressWarnings("unused")
public class MediaDiscoverer extends VLCObject<MediaDiscoverer.Event> {
private final static String TAG = "LibVLC/MediaDiscoverer";
......@@ -34,6 +36,35 @@ public class MediaDiscoverer extends VLCObject<MediaDiscoverer.Event> {
}
}
public static class Service {
public static class Category {
/** devices, like portable music player */
public static final int Devices = 0;
/** LAN/WAN services, like Upnp, SMB, or SAP */
public static final int Lan = 1;
/** Podcasts */
public static final int Podcasts = 2;
/** Local directories, like Video, Music or Pictures directories */
public static final int LocalDirs = 3;
}
public final String name;
public final String longName;
public final int category;
private Service(String name, String longName, int category)
{
this.name = name;
this.longName = longName;
this.category = category;
}
}
@SuppressWarnings("unused") /* Used from JNI */
private static Service createServiceFromNative(String name, String longName, int category)
{
return new Service(name, longName, category);
}
public interface EventListener extends VLCEvent.Listener<MediaDiscoverer.Event> {}
private MediaList mMediaList = null;
......@@ -111,9 +142,19 @@ public class MediaDiscoverer extends VLCObject<MediaDiscoverer.Event> {
nativeRelease();
}
/**
* Get media discoverer services by category
* @param category see {@link MediaDiscoverer.Service.Category}
*/
@Nullable
public static Service[] getServices(LibVLC libVLC, int category) {
return nativeGetServices(libVLC, category);
}
/* JNI */
private native void nativeNew(LibVLC libVLC, String name);
private native void nativeRelease();
private native boolean nativeStart();
private native void nativeStop();
private static native Service[] nativeGetServices(LibVLC libVLC, int category);
}
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