Coder
Coder

Reputation: 896

Is there a way to get LibVlc loaded buffer percentage?


I'm currently making a city webcam app which uses libVlc to display the rtsp stream coming from the city webcams. My question is, it is possible to get the actual loaded state of the stream? I would like to show to the user. I can see in Android Studio runLog that there is some kind of buffering but cannot find in the code.

D/VLC: core input: Buffering 56%
D/VLC: core input: Buffering 58%
D/VLC: core input: Buffering 61%
D/VLC: core input: Buffering 64%
D/VLC: core input: Buffering 66%
D/VLC: core input: Buffering 69%
D/VLC: core input: Buffering 72%
D/VLC: core input: Buffering 72%
D/VLC: core input: Buffering 77%

Upvotes: 3

Views: 2879

Answers (3)

mehmoodnisar125
mehmoodnisar125

Reputation: 1529

I add this version of vlc android sdk

compile 'de.mrmaffen:vlc-android-sdk:2.0.6'

 private static class MyPlayerListener implements MediaPlayer.EventListener {

    private WeakReference<VlcPlayerActivity> mOwner;

    public MyPlayerListener(VlcPlayerActivity owner) {
        mOwner = new WeakReference<VlcPlayerActivity>(owner);
    }

    @Override
    public void onEvent(MediaPlayer.Event event) {
        VlcPlayerActivity player = mOwner.get();

        switch (event.type) {
            case MediaPlayer.Event.Buffering:
                Log.d(TAG, ""+event.getBuffering());
                break;
            case MediaPlayer.Event.EndReached:
                Log.d(TAG, "MediaPlayerEndReached");
                player.releasePlayer();
                break;
            case MediaPlayer.Event.Playing:
            case MediaPlayer.Event.Paused:
            case MediaPlayer.Event.Stopped:
            default:
                break;
        }
    }
}

Upvotes: 1

Chirag Maheshwari
Chirag Maheshwari

Reputation: 421

This is for libvlc:2.1.1. you can get the buffer percentage using something like this ->

  • Implement MediaPlayer.EventListener on your video player activity.
  • Attach your media player event listener to current activity: mMediaPlayer.setEventListener(this);
  • Override onEvent method in your activity
  • In that method you can get the buffer float using event.getBuffering():

    @Override
    public void onEvent(MediaPlayer.Event event) {
        switch(event.type) {
            case MediaPlayer.Event.Buffering:
                Log.d("BUFFERING", ""+event.getBuffering());
                break;
        }
    }
    

Upvotes: 5

RSATom
RSATom

Reputation: 867

You should attach to libvlc_MediaPlayerBuffering event.

Upvotes: 1

Related Questions