download - Getting exception "unexpected end of stream" while downloading video in android -


I tried to download a video server that is larger video about 250MB in my Android app to 300mb. My code works fine from around 30 MB to 40 MB, but when I download large video I get an exception. Unexpected end of exceptions have been:

10-28 10: 11: 57.222: D / error .... (4617): java.io.IOException: Stream 10-28 10: 11: 57.227: W / Systems. Er (4617): java.io.IOException: Unexpected End Stream 10-28 10: 11: 57.232: W / Systems. Er (4617): On libcore.net. Http.FixedLengthInputStream .read (FixedLengthInputStream.java:48) 10-28 10: 11: 57.232: W / System.err (4617): On java.io.BufferedInputStream.read (BufferedInputStream.java:304) 10-28 10: 11: 57.237: W / Systems. Er (4617): at java.io.InputStream.read (InputStream.java:163) 10-28 10: 11: 57.237: W / Systems. Er (4617): at com.photography.khalid PreviewVideo.DownloadFile (PreviewVideo.java:1079) 10-28 10: 11: 57.237: W / System.err (4617): $ DownLoadVideoFile.doInBackground (PreviewVideo.java:1121) 10-28 on com.photography.khalid.PreviewVideo 10: 11: 57.242: W / System.err (4617): 11 :: 57.242: com.photography.khalid.PreviewVideo $ DownLoadVideoFile.doInBackground (PreviewVideo.java:1) 10-28 10 W / System.err (4617 ): 10-28 on Android.os.AsyncTask $ 2.call (AsyncTask.java:264) 10: 11: 57.242: W / System.err (4617): java.util.concurrent.FutureTask at $ Sync.innerRun ( FutureTask.Java: 305) 10-28 10: 11: 57.242: W / Systems. ER (4617): On java.util.concurrent.FutureTask.run (FutureTask.java:137) 10-28 10: 11: 57.247: W / System.err (4617): 11 :: 57.247: W / Systemkerr (4617): java.util.concurrent at android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java208) at 10-28 10. ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1076) 10-28 10: 11: 57.252: W / System.err (4617): $ Worker.run (ThreadPoolExecutor.java:569) 10-28 on java.util.concurrent.ThreadPoolExecutor 10: 11: 57.252: W / Systems. ARR (4617): On JavaklangkThreadkrun (Thredkjawa: 856)

I tried to find the flow on the stack therefore using this link, but Still, errors are found on large size videos.

My code is given bellow

  public void DownloadFile (string fileURL, string filename) {try {string R OotDir = Environmental .getExternalStorageDirectory () + file. Separator + "photography"; / * String root directory = reference.gatecash () + file. Separator + "photography"; * / File root file = new file (rootdair); RootFile.mkdir (); // file root = environment .getExternalStorage directory (); URL U = new URL (fileURL); System.setProperty ("http.keepAlive", "Wrong"); HttpURL connection c = (HttpURL connection) u.openConnection (); // Open a connection to that URL // URLConnection c = u.openConnection (); C.setUseCaches (wrong); C.setDoInput (true); C.setRequestMethod ("post"); C.setDoOutput (true); C.connect (); Int contentByte = c.getContentLength (); FileOutputStream f = New FileOutputStream (new file (rootfile, "temporary" + filename)); //f = openFileOutput ("temp" + filename, reference.modE_PRIVATE); InputStream = c.getInputStream (); BufferedInputStream Instream = New BufferedInputStream (in, 1024 * 10); Byte [] buffer = new byte [10 * 1024]; Int len1 = 0; While ((len1 = inStream.read (buffer))! = -1) {f.write (buffer, 0, lane1); Log D. ProgressBarStatus + = (len1 * 100.0) / (contentByte) 0.0; progressBarHorizontal.setProgress ((int) progressBarStatus); progressBar2 ("file data", buffer.Testring ("+", "barstatus" + progress barstas) setProgress ((int) progressBarStatus); If (isTaskCancelled) {failToDownload = 1; break;}} F.flush (); f.close (); inStream.close ();} catch (exception e) {log (d. "error ...." Ikoststring ()); e.printStackTrace (); failToDownload = 1;}}  

If you have any suggestions comes from the well thanks

I have found that using manual code, I can not download long videos, which we have to use download manager here I shared a helpful link to get my work


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -