Open ghost opened 9 years ago
Try mVideoView.setBufferSize(1000);
@ram10609601
If Resolve, be sure to post informing us, or if you find another solution. Remember to close the inssue.
Thanks Florida for replying. I appreciate the solution. It really did the trick but with RTSP protocol (RTMP is too slow). Now the latency is reduced to 2-3 sec. But If we continue the collaboration for long time (around 10-20 mins), the latency gradually increases (5, 8, 13,....and so on). We probably need to clear the buffer (Not sure). Please test this scenario also, and update here accordingly. Thanks.
Take a look at this code, maybe he can help on something. Maybe making some adjustments in it, you can deiminuit the buffering time for one second for example. But if the video or your connection is slow, none of this will help.
public boolean isFirst_Loading_Complete = false;
private boolean isStart; //adicionado
... implements MediaPlayer.OnBufferingUpdateListener ...
public void onCreate
...
mVideoView.setOnBufferingUpdateListener(this);
...
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
if(isFirst_Loading_Complete) {
loadRateView.setText(percent + "%");
}
if (percent < 5) {
mVideoView.pause();
isStart = true;
if(isFirst_Loading_Complete) {
pb.setVisibility(View.VISIBLE);
downloadRateView.setVisibility(View.VISIBLE);
loadRateView.setVisibility(View.VISIBLE);
loadRateView.setText(percent + "%");
}
} else if (percent < 20) {
// loadRateView.setText(percent + "%");
// allows the user to actively aware Play
} else { // > 20%
// cho phep play + tat spin
mVideoView.start();
pb.setVisibility(View.GONE);
downloadRateView.setVisibility(View.GONE);
loadRateView.setVisibility(View.GONE);
complete_background_im.setVisibility(View.GONE);
isFirst_Loading_Complete = true;// true because first loading is displayed
first_open_probar.setVisibility(View.INVISIBLE);
first_open_probar_text.setVisibility(View.INVISIBLE);
}
}
I do not know if you can help, but it's to get a better idea of the possibilities.
For an initial latency of 2 seconds is very good, I do not know if it is possible to decrease more.
@Florida, I tried your code, but it did not help. Still initial latency is around 1-2 seconds but after 10 mins streaming, latency becomes around 8-10 seconds. As soon as buffer gets full It starts increasing latency. Any idea, how can we flush/clear buffer when It gets full. Below is my code. Vitamio Audio_Demo sample code-
/* Global fields */ public boolean isFirst_Loading_Complete = false; private boolean isStart; private boolean is_playing_firstTime = false; . . . private void playAudio(Integer media) { try { switch (media) { case LOCAL_AUDIO: path = "rtsp://219.65.90.226:1935/app1/myStream"; mMediaPlayer = new MediaPlayer(this); mMediaPlayer.setDataSource(path); mMediaPlayer.prepare(); mMediaPlayer.setBufferSize(5000); //set buffer size mMediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
if(mMediaPlayer.isPlaying()){
is_playing_firstTime = true;
}else{
System.out.println("MP stopped");
}
System.out.println(percent + "% 0");
if(isFirst_Loading_Complete) {
System.out.println(percent + "% 1");
}
if (percent < 5) {
mMediaPlayer.pause();
isStart = true;
if(isFirst_Loading_Complete) {
System.out.println(percent + "% 2");
}
}
else if (percent < 20) {
// loadRateView.setText(percent + "%");
// allows the user to actively aware Play
} else { // > 20%
// cho phep play + tat spin
mMediaPlayer.start();
System.out.println(percent + "% 3");
isFirst_Loading_Complete = true;// true because first loading is displayed
mMediaPlayer.setBufferSize(5000);
System.out.println(percent + "% 4");
}
}
});
mMediaPlayer.start();
break;
case RESOURCES_AUDIO:
/**
* TODO: Upload a audio file to res/raw folder and provide its resid in
* MediaPlayer.create() method.
*/
//Bug need fixed
mMediaPlayer = createMediaPlayer(this, R.raw.test_cbr);
mMediaPlayer.start();
}
tx.setText("Playing audio...");
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
}
}
@ram10609601 How did you solve this problem? I meet the same issue!
Is there any method (or possible way) to reduce the buffer size on Android application/OS level in Vitamio streaming library? (Please help me out, It's too urgent. Any help would be greatly appreciated.)