Online Video Streaming from http url with caching in android Application

android, android-mediaplayer, progressive-download, video-streaming

Solution

Just use AndroidVideoCache:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    try {
        Cache cache = new FileCache(new File(getExternalCacheDir(), VIDEO_CACHE_NAME));
        HttpUrlSource source = new HttpUrlSource(VIDEO_URL);
        proxyCache = new HttpProxyCache(source, cache);
        videoView.setVideoPath(proxyCache.getUrl());
        videoView.start();
    } catch (ProxyCacheException e) {
        Log.e(LOG_TAG, "Error playing video", e);
    }
}

@Override
public void onDestroy() {
    super.onDestroy();

    if (proxyCache != null) {
        proxyCache.shutdown();
    }
}

Problem

In my Application, I am showing videos to user from an online source in progressive manner (I have an Http url for every video). It is quite possible with SurfaceView and MediaPlayer in combination and also with VideoView as an alternative. But I want to keep the streamed video available in the cache for the future uses [without making any separate call for downloading video as its already being downloaded by MediaPlayer or VideoView while streaming] Any Idea about saving video from stream buffered by MediaPlayer ??

Original source