1
    VideoView vidView;
    MediaController mediaController;
    LinearLayout btn_download;
    UserService userService;

       userService = ApiUtils.getUserService();
       if(mediaController == null){
          mediaController = new MediaController(ColumnPipeInstallationActivity.this);
          mediaController.setAnchorView(vidView);
       }
    vidView.setMediaController(mediaController);
    Uri vidUri = Uri.parse(url);
    vidView.setVideoURI(vidUri);<----on create of activity video will start to play. Is it possible to get size of the file.
    vidView.start();}}

onClick of button is it possible to download the file to the device?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
  • Yes, you can download file to the device. If you check in Google, you will get some sample code or good reference about how to download file from url. – Ajay Mehta Jan 04 '19 at 07:07

3 Answers3

1

You could try this,

public long getFileSizeFromUrl(URL url) {
    HttpURLConnection conn = null;
    try {
      conn = (HttpURLConnection) url.openConnection();
      conn.setRequestMethod("HEAD");
      return conn.getContentLengthLong();
    } catch (IOException e) {
       //Maybe throw the exception, or just stacktrace it. Your call
    } finally {
      if (conn != null) {
        conn.disconnect();
      }
    }
}
Sandesh Baliga
  • 579
  • 5
  • 20
1

You are trying to get content-length field

Try this if the answer of P Sandesh Baliga does not work

Liar
  • 1,235
  • 1
  • 9
  • 19
0

Use the following code to get the length of video on buttonClick()

 URL url = new URL("URL_OF_YOUR_VIDEO");
            HttpURLConnection c = (HttpURLConnection) url.openConnection();
            c.setRequestProperty("Accept-Encoding", "identity");
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();
            int lenghtOfFile = c.getContentLength();
            Log.w("getContentLength",""+lenghtOfFile);

Hope this works!

ppreetikaa
  • 1,149
  • 2
  • 15
  • 22