I play a Live RTSP stream from VLC on a PC to the Android MediaPlayer class (as on the same local network). It plays smoothly without errors - the problem is that the decoded video on the screen is between 5 and 7 seconds behind the live one.
From debugging and callbacks, I see that the current data arrives at the device <1 s after running mMediaPlayer.prepareAsync()
. This is when the MediaPlayer class begins to determine in what format a stream with such dimensions is located, etc. Then, before the video is displayed on the screen (between 5 and 7 seconds later), onPrepared()
is onPrepared()
, where I call mMediaPlayer.start()
. It appears that this start()
plays the video that was originally recorded from the beginning of the preparation phase.
I tried seekTo(5000)
both before and after start()
, but it does not affect the delay at all.
For a real-time video call application, the setup delay for a few seconds is fine, but I did not succeed in lagging after the video was presented.
public void surfaceCreated(SurfaceHolder holder) { mMediaPlayer = new MediaPlayer(); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.setOnInfoListener(this); mMediaPlayer.setOnErrorListener(this); mMediaPlayer.setOnVideoSizeChangedListener(this); mMediaPlayer.setOnBufferingUpdateListener(this); mMediaPlayer.setDataSource("rtsp://192.168.1.4:5544/test"); mMediaPlayer.setDisplay(holder); mMediaPlayer.setScreenOnWhilePlaying(true); mMediaPlayer.setOnPreparedListener(this); mMediaPlayer.setOnCompletionListener(this); mMediaPlayer.prepareAsync(); ... public void onPrepared(MediaPlayer mediaplayer) { mMediaPlayer.start(); ...
Any ideas on how I can reduce this lag, or look for the end of what MediaPlayer is buffering? My device is 3.1, minSdkVersion is 2.2.
EDIT:
In AwesomePlayer.cpp (2s and 8s) I found some high and low watermarks. As a quick test, I hacked libstagefright.so to do these 0.1s and 1s. However, this did not affect the delay. My search continues ...
barkside
source share