I'm trying to play a video with media player while is downloading on sdcard. I give setdatasource from sdcard.. Media player play the video but after a few seconds stops the video, but media player still playing but content is on break. how can I play the video again where it left off?
    private void downloadVideo(String url) {
    try {
        URL url1 = new URL(url);
        long startTime = System.currentTimeMillis();
        Log.i("TAG", "image download beginning: " + url);
        URLConnection conn = url1.openConnection();
        conn.setReadTimeout(5000);
        conn.setConnectTimeout(30000);
        File path = android.os.Environment.getExternalStorageDirectory();
        InputStream is = conn.getInputStream();
        BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
        File directories = new File(path + "/sequence/");
        if (!directories.exists()) {
            directories.mkdirs();
        }
        FileOutputStream outStream = new FileOutputStream(new File(
                directories, "test2.mp4"));
        byte[] buff = new byte[5 * 1024];
        // byte[] buff = new byte[1024 * 24];
        int len;
        while ((len = inStream.read(buff)) != -1) {
            outStream.write(buff, 0, len);
        }
        outStream.flush();
        outStream.close();
        inStream.close();
        Log.i("TAG",
                "download completed in "
                        + ((System.currentTimeMillis() - startTime) / 1000)
                        + " sec");
    } catch (MalformedURLException e) {
        Log.d("Malformed", e.toString());
    } catch (IOException e) {
        Log.d("IOException", e.toString());
    }
}
code for playing video
        Runnable task = new Runnable() {
        public void run() {
            try {
                File path = android.os.Environment
                        .getExternalStorageDirectory();
                // http://www.pocketjourney.com/downloads/pj/video/famous.3gp
                // http://www.youtube.com/watch?v=Fvh38W4yKvc
                // http://mconnect123456.s3.amazonaws.com/4532happyfit2.mp4
                mp.reset();
                mp.setDataSource(path + "/sequence/test2.mp4");
                // mp.setDataSource("http://mconnect123456.s3.amazonaws.com/4532happyfit2.mp4");
                mp.prepare();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            mp.start();
            while (!mp.isPlaying()) {
                Log.d("Playing", "playing");
            }
        }
    };
    worker.schedule(task, 5, TimeUnit.SECONDS);
 
     
    