title: Java Android download video in parts and Play combined
body: <p>I don't know how to do. Please suggest how to download a large video file in parts and play all parts one by one. 
  Actually I have to stream FTP large file in Android <code>VideoView</code>. I have searched a lot and found that android do not support FTP streaming.</p>
  
  <p>So, I tried to download the file in multiple parts and play them one by one. But the problem is that only first part of file plays, others don't. Please suggest.</p>
  
  <p>Code to download file in parts.</p>
  
  <pre><code>URL url = new URL(fileUrl);
  URLConnection ucon = url.openConnection();
  InputStream is = ucon.getInputStream();
  BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
  FileOutputStream outStream = new FileOutputStream(fileName);
  byte[] buff = new byte[5 * 1024];
  int len;
  
  int maxLenth = 10000;      //Some random value
  int counter = 0;
  
  //Read bytes (and store them) until there is nothing more to read(-1)
   while ((len = inStream.read(buff)) != -1) {
        outStream.write(buff, 0, len);
        counter ++;
        Log.d(TAG, "Counter: " + counter);
  
        if(counter == maxLenth) {
            counter = 0;
            outStream.flush();
            outStream.close();
  
            fileName = new File(directory.getAbsolutePath() + "/"
                          + context.getResources().getString(R.string.app_name) + "_"
                          + System.currentTimeMillis() + "." + format);
            fileName.createNewFile();
            outStream = new FileOutputStream(fileName);
        }
    }
  </code></pre>
  
  <p>And when the files are downloaded, I tried to update the list to play videos when at least 1 file is downloaded. listFiles contains list of all the dowloaded files.</p>
  
  <pre><code>    Uri uri = Uri.parse(listFiles.get(0));
      videoView.setVideoURI(uri);
      videoView.start();
  
      videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mediaPlayer) {
              counter ++;
              if(counter &lt; listFiles.size()) {
                  Uri uri = Uri.parse(listFiles.get(counter));
                  videoView.setVideoURI(uri);
                  videoView.start();
              }
          }
      });
  </code></pre>
  
  <p>I don't know why the downloaded files after file 1 don't play. They don't play even in the PC. I don't know what wrong am I doing.</p>