I am facing the issue that whenever a stream is played by my app on Android 4.0+ the OnPrepare
method from MediaPlayer.OnPreparedListener
is called even before a stream is loaded and thus i am unable to indicated the user that the stream downloading/buffering is in process. I have already found a question of the same kind but not answered
Here is a what i am doing.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
playVideo(someRtspUrl);
}
private void playVideo(String url) {
// if app is running on Google TV then change RTSP link to HLS
if (url.contains("rtsp")) {
// split the RTSP URL and make it as HLS
String videoUrlParts[] = url.split("\\?");
url = videoUrlParts[0].replace("rtsp", "http") + "/playlist.m3u8";
if (videoUrlParts.length > 1)
url += "?" + videoUrlParts[1];
} mVideoView.setVideoURI(Uri.parse(url));
mVideoView.requestFocus();
mVideoView.setOnCompletionListener(this);
mVideoView.setOnPreparedListener(this);
}
@Override
public void onPrepared(MediaPlayer player) {
dismissProgressDialog();
mVideoView.start();
}
This Code is Working fine on Google TV and other Android 3.0+ and < 4.0+ device