视频不是从URL下载的

时间:2015-02-27 10:09:35

标签: java android

我想从网址下载视频我的功能如下

String fileURL = "http://192.168.1.2/UserFiles/Videos/OutputVideo/Birthday%20Bash5tV3fgjf4Sfi11sC.mp4";

String fileName = "Abc.mp4";

public void downloadFile(String fileURL, String fileName){
        Toast.makeText(getApplicationContext(), "Download File", Toast.LENGTH_LONG).show();

        try
        {
            URL u = new URL(fileURL);
            URLConnection ucon = u.openConnection();
            //Define InputStreams to read from the URLConnection.
            // uses 3KB download buffer
            File file =new File(Environment.getExternalStorageDirectory() + File.separator + "/Planetskool/Media/Videos/"+fileName);
            InputStream is = ucon.getInputStream();
            BufferedInputStream inStream = new BufferedInputStream(is, 1024 * 5);
            FileOutputStream outStream = new FileOutputStream(file);
            byte[] buff = new byte[5 * 1024];

            //Read bytes (and store them) until there is nothing more to read(-1)
            int len;
            while ((len = inStream.read(buff)) != -1)
            {
                outStream.write(buff,0,len);
            }

            //clean up
            outStream.flush();
            outStream.close();
            inStream.close();
        }
        catch (Exception se)
        {
            se.printStackTrace();
        }

    }

以0kb的速度下载该视频的错误

2 个答案:

答案 0 :(得分:0)

可能会发生三件事

  1. 缺少互联网许可
  2. 缺少写入外部存储权限
  3. “/ Planetskool / Media / Videos /”目录不存在,首先创建目录。
  4. http://192.168.1.2不是互联网网址检查您的网址

答案 1 :(得分:0)

使用异步方法从URL下载文件。