Esempio n. 1
0
/* TODO: NOT IN VLC API */
void
Java_org_videolan_libvlc_MediaPlayer_nativePlayMRL(JNIEnv *env, jobject thiz,
                                                   jstring mrl,
                                                   jobjectArray mediaOptions)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    /* New Media */
    const char* p_mrl = (*env)->GetStringUTFChars(env, mrl, 0);
    libvlc_media_t* p_md = libvlc_media_new_location(p_obj->p_libvlc, p_mrl);

    /* media options */
    if (mediaOptions != NULL)
        add_media_options(p_md, env, mediaOptions);

    (*env)->ReleaseStringUTFChars(env, mrl, p_mrl);

    /* Connect the media event manager. */
    /* TODO use VlcObject events */
    libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
    static const libvlc_event_type_t mp_media_events[] = {
        libvlc_MediaParsedChanged,
        libvlc_MediaMetaChanged,
    };
    for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
        libvlc_event_attach(ev_media, mp_media_events[i], vlc_event_callback, NULL);

    libvlc_media_player_set_media(p_obj->u.p_mp, p_md);
    libvlc_media_release(p_md);

    libvlc_media_player_play(p_obj->u.p_mp);
}
jobject
Java_org_videolan_libvlc_MediaPlayer_nativeGetTitles(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
    libvlc_title_description_t **pp_titles = NULL;
    int i_nb_titles;
    jobjectArray array;

    if (!p_obj)
        return NULL;

    i_nb_titles = libvlc_media_player_get_full_title_descriptions(p_obj->u.p_mp,
                                                                  &pp_titles);
    if (i_nb_titles <= 0)
        return NULL;

    array = (*env)->NewObjectArray(env, i_nb_titles,
                                   fields.MediaPlayer.Title.clazz, NULL);
    if (!array)
        goto error;

    for (int i = 0; i < i_nb_titles; ++i)
    {
        jobject jtitle = mediaplayer_title_to_object(env, pp_titles[i]);

        if (jtitle)
            (*env)->SetObjectArrayElement(env, array, i, jtitle);
    }

error:
    if (pp_titles)
        libvlc_title_descriptions_release(pp_titles, i_nb_titles);
    return array;
}
Esempio n. 3
0
void
Java_org_videolan_libvlc_MediaPlayer_stop(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    /* TODO: REMOVE */
    libvlc_media_t* p_md = libvlc_media_player_get_media(p_obj->u.p_mp);
    if (p_md)
    {
        libvlc_event_manager_t *ev_media = libvlc_media_event_manager(p_md);
        static const libvlc_event_type_t mp_media_events[] = {
            libvlc_MediaParsedChanged,
            libvlc_MediaMetaChanged,
        };
        for(int i = 0; i < (sizeof(mp_media_events) / sizeof(*mp_media_events)); i++)
            libvlc_event_detach(ev_media, mp_media_events[i], vlc_event_callback, NULL);
        libvlc_media_release(p_md);
        libvlc_media_player_set_media(p_obj->u.p_mp, NULL);
    }

    libvlc_media_player_stop(p_obj->u.p_mp);
}
Esempio n. 4
0
void
Java_org_videolan_libvlc_MediaPlayer_nativeRelease(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    /* TODO: REMOVE */
    libvlc_event_manager_t *ev = libvlc_media_player_event_manager(p_obj->u.p_mp);
    static const libvlc_event_type_t mp_events[] = {
        libvlc_MediaPlayerPlaying,
        libvlc_MediaPlayerPaused,
        libvlc_MediaPlayerEndReached,
        libvlc_MediaPlayerStopped,
        libvlc_MediaPlayerVout,
        libvlc_MediaPlayerPositionChanged,
        libvlc_MediaPlayerTimeChanged,
        libvlc_MediaPlayerEncounteredError,
        libvlc_MediaPlayerESAdded,
        libvlc_MediaPlayerESDeleted,
    };

    for(int i = 0; i < (sizeof(mp_events) / sizeof(*mp_events)); i++)
        libvlc_event_detach(ev, mp_events[i], vlc_event_callback, NULL);
    libvlc_media_player_release(p_obj->u.p_mp);

    VLCJniObject_release(env, thiz, p_obj);
}
vlcjni_object *
VLCJniObject_newFromLibVlc(JNIEnv *env, jobject thiz,
                           libvlc_instance_t *p_libvlc,
                           const char **pp_error)
{
    vlcjni_object *p_obj;
    libvlc_event_manager_t *ev;

    p_obj = VLCJniObject_getInstance(env, thiz);
    if (p_obj)
    {
        *pp_error = "VLCObject.mInstanceID already exists";
        return NULL;
    }

    p_obj = calloc(1, sizeof(vlcjni_object));
    if (!p_obj)
    {
        *pp_error = "vlcjni_object calloc failed";
        goto error;
    }

    p_obj->p_owner = calloc(1, sizeof(vlcjni_object_owner));
    if (!p_obj->p_owner)
    {
        *pp_error = "vlcjni_object_owner calloc failed";
        goto error;
    }

    p_obj->p_libvlc = p_libvlc;
    libvlc_retain(p_libvlc);

    if (fields.VLCObject.getWeakReferenceID)
    {
        jobject weakCompat = (*env)->CallObjectMethod(env, thiz,
                                           fields.VLCObject.getWeakReferenceID);
        if (weakCompat)
        {
            p_obj->p_owner->weakCompat = (*env)->NewGlobalRef(env, weakCompat);
            (*env)->DeleteLocalRef(env, weakCompat);
        }
    } else
        p_obj->p_owner->weak = (*env)->NewWeakGlobalRef(env, thiz);
    if (!p_obj->p_owner->weak && !p_obj->p_owner->weakCompat)
    {
        *pp_error = "No VLCObject weak reference";
        goto error;
    }

    VLCJniObject_setInstance(env, thiz, p_obj);

    *pp_error = NULL;
    return p_obj;

error:
    VLCJniObject_release(env, thiz, p_obj);
    return NULL;
}
void
Java_org_videolan_libvlc_MediaDiscoverer_nativeStop(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_media_discoverer_stop(p_obj->u.p_md);
}
Esempio n. 7
0
jboolean
Java_org_videolan_libvlc_MediaPlayer_isSeekable(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return false;

    return !!libvlc_media_player_is_seekable(p_obj->u.p_mp);
}
Esempio n. 8
0
jlong
Java_org_videolan_libvlc_MediaPlayer_getLength(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -1;

    return (jlong) libvlc_media_player_get_length(p_obj->u.p_mp);
}
Esempio n. 9
0
jfloat
Java_org_videolan_libvlc_MediaPlayer_getRate(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return 0.0f;

    return libvlc_media_player_get_rate(p_obj->u.p_mp);
}
Esempio n. 10
0
jfloat
Java_org_videolan_libvlc_MediaPlayer_getPosition(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -1;

    return (jfloat) libvlc_media_player_get_position(p_obj->u.p_mp);
}
Esempio n. 11
0
jint
Java_org_videolan_libvlc_MediaPlayer_getTitleCount(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -1;

    return libvlc_media_player_get_title_count(p_obj->u.p_mp);
}
Esempio n. 12
0
void
Java_org_videolan_libvlc_MediaPlayer_nextChapter(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_media_player_next_chapter(p_obj->u.p_mp);
}
jboolean
Java_org_videolan_libvlc_MediaDiscoverer_nativeStart(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return false;

    return libvlc_media_discoverer_start(p_obj->u.p_md) == 0 ? true : false;
}
Esempio n. 14
0
jint
Java_org_videolan_libvlc_MediaPlayer_getVolume(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -1;

    return (jint) libvlc_audio_get_volume(p_obj->u.p_mp);
}
jint
Java_org_videolan_libvlc_MediaPlayer_nativeGetAudioTrack(JNIEnv *env,
                                                         jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -2;

    return libvlc_audio_get_track(p_obj->u.p_mp);
}
Esempio n. 16
0
void
Java_org_videolan_libvlc_MediaPlayer_setMusicMode(JNIEnv *env, jobject thiz,
                                               jint mode)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_audio_set_music_mode(p_obj->u.p_mp, (int) mode);
}
jlong
Java_org_videolan_libvlc_MediaPlayer_nativeGetSpuDelay(JNIEnv *env,
                                                       jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return 0;

    return libvlc_video_get_spu_delay(p_obj->u.p_mp);
}
jboolean
Java_org_videolan_libvlc_MediaPlayer_nativeSetSpuTrack(JNIEnv *env,
                                                       jobject thiz, jint index)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return false;

    return libvlc_video_set_spu(p_obj->u.p_mp, index) == 0 ? true : false;
}
Esempio n. 19
0
/* Returns 0 if the channel was set, -1 if it was out of range or error */
jint
Java_org_videolan_libvlc_MediaPlayer_setChannel(JNIEnv *env, jobject thiz,
                                               jint channel)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -1;

    return (jint) libvlc_audio_set_channel(p_obj->u.p_mp, (int) channel);
}
Esempio n. 20
0
void
Java_org_videolan_libvlc_MediaPlayer_setChannelMute(JNIEnv *env, jobject thiz,
                                               jint channel, jint mute)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_audio_set_channel_mute(p_obj->u.p_mp, (int) channel, (int) mute);
}
jint
Java_org_videolan_libvlc_MediaPlayer_nativeGetVideoTracksCount(JNIEnv *env,
                                                              jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return 0;

    return libvlc_video_get_track_count(p_obj->u.p_mp);
}
Esempio n. 22
0
void
Java_org_videolan_libvlc_MediaPlayer_playerNavigate(JNIEnv *env, jobject thiz,
                                                    jint navigate)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_media_player_navigate(p_obj->u.p_mp, (unsigned) navigate);
}
Esempio n. 23
0
void
Java_org_videolan_libvlc_MediaPlayer_setTitle(JNIEnv *env, jobject thiz,
                                              jint title)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_media_player_set_title(p_obj->u.p_mp, title);
}
Esempio n. 24
0
void
Java_org_videolan_libvlc_MediaPlayer_setPosition(JNIEnv *env, jobject thiz,
                                                 jfloat pos)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_media_player_set_position(p_obj->u.p_mp, pos);
}
jobject
Java_org_videolan_libvlc_MediaPlayer_nativeGetSpuTracks(JNIEnv *env,
                                                        jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return NULL;

    return mediaplayer_tracklist_to_object(env,
                libvlc_video_get_spu_description(p_obj->u.p_mp));
}
jboolean
Java_org_videolan_libvlc_MediaPlayer_nativeSetSpuDelay(JNIEnv *env,
                                                       jobject thiz,
                                                       jlong delay)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
       return false;

    return libvlc_video_set_spu_delay(p_obj->u.p_mp, delay) == 0 ? true : false;
}
Esempio n. 27
0
jint
Java_org_videolan_libvlc_MediaPlayer_getChapterCountForTitle(JNIEnv *env,
                                                             jobject thiz,
                                                             jint title)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return -1;

    return libvlc_media_player_get_chapter_count_for_title(p_obj->u.p_mp, title);
}
void
Java_org_videolan_libvlc_MediaPlayer_nativeSetMedia(JNIEnv *env,
                                                    jobject thiz,
                                                    jobject jmedia)
{
    libvlc_media_t *p_m = NULL;
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    if (jmedia)
    {
        vlcjni_object *p_m_obj = VLCJniObject_getInstance(env, jmedia);

        if (!p_m_obj)
            return;
        p_m = p_m_obj->u.p_m;
    }

    libvlc_media_player_set_media(p_obj->u.p_mp, p_m);
}
void
Java_org_videolan_libvlc_MediaPlayer_nativeSetVideoTitleDisplay(JNIEnv *env,
                                                                jobject thiz,
                                                                jint jposition,
                                                                jint jtimeout)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj)
        return;

    libvlc_media_player_set_video_title_display(p_obj->u.p_mp, jposition,
                                                jtimeout);
}
void
Java_org_videolan_libvlc_VLCObject_nativeDetachEvents(JNIEnv *env, jobject thiz)
{
    vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);

    if (!p_obj || !p_obj->p_owner->p_event_manager
        || !p_obj->p_owner->p_events)
        return;

    for(int i = 0; p_obj->p_owner->p_events[i] != -1; ++i)
        libvlc_event_detach(p_obj->p_owner->p_event_manager,
                            p_obj->p_owner->p_events[i],
                            VLCJniObject_eventCallback, p_obj);
    p_obj->p_owner->p_event_manager = NULL;
    p_obj->p_owner->p_events = NULL;
}