I am writing a code for background video play, for that I'm using VideoView. I'm getting the video URL from server and then parsing it to videoView. Obvious reason, it will take time to load.
private String videoViewUrl = null;
private VideoView videoView;
private MediaPlayer mp;
networkManager.getRequest(JSON_URL, new NetworkCallback() {
@Override
public void onSuccess(String result) {
try {
JSONObject obj = new JSONObject(result);
JSONObject themeObj = obj.getJSONObject("Theme");
JSONObject videoObj = themeObj.getJSONObject("Video");
videoViewUrl = videoObj.getString("VideoUrl");
// parse to videoview
videoView.setVideoURI(Uri.parse(videoViewUrl));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mp = mediaPlayer;
mediaPlayer.setLooping(true);
}
});
videoView.start();
@Override
protected void onResume() {
if (videoView != null)
videoView.resume();
super.onResume();
@Override
protected void onPause() {
if (videoView != null)
videoView.suspend();
super.onPause();
So when whenever I start my new activity and navigate back, video restarts and takes time to reload. Is there any way to minimize the buffer-time.