Search code examples
androidvlclibvlc

Enabling MediaPlayerBuffering event to be fired in android-vlc


I would like to subscribe for the MediaPlayer buffering event in the android vlc app.

I edited the EventHandler class and uncommented the event constant.

public static final int MediaPlayerBuffering            = 0x103; // ** uncommented this**
public static final int MediaPlayerPlaying                = 0x104;

I then added the the variable in libvlcjni.c

libvlc_event_manager_t *ev = libvlc_media_player_event_manager(mp);
static const libvlc_event_type_t mp_events[] = {
    libvlc_MediaPlayerPlaying,
    libvlc_MediaPlayerPaused,
    libvlc_MediaPlayerEndReached,
    libvlc_MediaPlayerStopped,
    libvlc_MediaPlayerVout,
    libvlc_MediaPlayerPositionChanged,
    libvlc_MediaPlayerEncounteredError,
    libvlc_MediaPlayerBuffering // **added this here**
};

recompiled the jni to get the so file and then built the vlc app but the event never seems to fire off.

Where else do I have to link to get the event fired when there is a buffering event due to lack of bandwidth.

I can see in logcat that it prints 1001 ms buffered in 6ms. But that is coming from the lower layer and not the java layer


Solution

  • had to add this in the libvlcjni.c file

    else if(ev->type == libvlc_MediaPlayeBuffering) {
        /* For determining the vout/ES track change */
        jstring sData = (*env)->NewStringUTF(env, "data");
        (*env)->CallVoidMethod(env, bundle, putFloat, sData, ev->u.media_player_buffer.new_cache);
        (*env)->DeleteLocalRef(env, sData);
    }
    

    hope this helps someone