开发者

Can I partially download a video from the Internet to preview it?

Is it possible to download only the first few megabytes of a video? I am writing a Java program th开发者_运维问答at will download a video more than 30 MB. However, before starting the download, I'd first like to download enough for a preview so that I can decide if I really need to download that video or not.


You can open url connection and read the amount of data that you need:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = url.inputStream();
int buf_size = 8192;
byte[] buf = new byte[buf_size];
while (baos.size() < MAX) {
  int len = is.read(buf, 0, buf_size);
  if (len == -1) break;
  baos.write(buf, 0, len);
}


this is a very open ended question. i'll give you a couple examples of how to download a video.

  1. direct link: if the video is a link, right click on the video link and select "save as" and save the file you're trying to download to your computer. That's the easiest way.

  2. embedded video: i'm a mac user, so i'm going to share an easy way to download any 'progressive' video without any added software or javascript. open a safari browser on a mac > select "window" > select "activity". Select the page that has the video you want to download from the list of pages in the list if there's more than one. Once you have located the correct page, expand it and among the list of files that were rendered, you should begin to see a file that says x MB of x MB being downloaded. You'll see lots of other files that rendered, such as images, etc, but the MB file is what you want to pay attention to since that is the video that is embedded on the page. Now, all you need to do is double click that file in the activity window and your download manager will open and it will begin to download the video to your desktop.

I'm sorry I don't have a solution for a PC and I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜