问题
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%
回答1:
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; } }
回答2:
You should attach to libvlc_MediaPlayerBuffering
event.
回答3:
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;
}
}
}
来源:https://stackoverflow.com/questions/42690992/is-there-a-way-to-get-libvlc-loaded-buffer-percentage