title: Playing a downloaded video Error: 1, -2147483648
body: <p>I'm trying to download a video file and then play it in an app, if I put the video file in the res folder I'm able to play it without a problem, however when I try and download the video then play it I get the VideoView Error: 1, -2147483648. </p>
  
  <p>This is the code I use to download the video:</p>
  
  <pre><code>    try
      {
  
          URL url = new URL(videoURL);
          URLConnection conexion = url.openConnection();
          conexion.connect();
  
          int lengthOfFile = conexion.getContentLength();
          Log.d("ANDRO_ASYNC", "Length of file: " + lengthOfFile);
  
          InputStream input = new BufferedInputStream(url.openStream());
  
  
  
  
          final File dir = new File(this.getFilesDir() + "/videos");
          dir.mkdirs(); //create folders where write files
          final File file = new File(dir, "my_video.mp4");
  
          Log.d("writePath", file.getPath());
  
          FileOutputStream output = new FileOutputStream(file);
  
          byte data[] = new byte[1024];
          long total = 0;
  
          while((count = input.read(data)) != -1)
          {
              total += count;
              //publishProgress("" + (int)((total*100) / lengthOfFile));
              output.write(data, 0, count);
          }
  
          output.flush();
          output.close();
          input.close();
  
          Log.d("download", "finished");
  
      }
      catch(Exception e)
      {
  
          Log.d("Exception", e.getMessage());
      }
  </code></pre>
  
  <p>This appears to complete successfully, but when I try to play the file with the followed code, I get the error.</p>
  
  <pre><code> // Play Video
      videoView = (VideoView)findViewById(R.id.surface_view);
      //
  
      File f = new File("/data/data/com.companyname.appname/files/videos/videoFilename.mp4");
  
  
  
      if(f.exists())
      {
          long len = f.length();
          String length = String.valueOf(len);
          Log.d("file", "exists");
          Log.d("length", (String)length);
      }
      else
      {
          Log.d("file", "does not exist");
      }
  
      //
  
  
  
  
  
  
      videoView.setMediaController(new MediaController(this));
  
  
      videoView.setVideoPath(f.getPath());
      videoView.start();
  </code></pre>
  
  <p>As seen in the code, before playing I check if the file exists and also it's size (it is the same size as the downloaded file) but it won't play, I'm guessing the file is corrupted but I don't know why. </p>
  
  <p>I have the following permissions set in the manifest</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_INTERAL_STORAGE" /&gt;
  </code></pre>