是否有任何第三方库在Android下载视频

时间:2017-12-06 06:57:32

标签: android android-fragments android-library android-sdk-manager

我正在寻找第三方图书馆来下载视频网址。

目前正在使用手动制作视频下载。

如果您知道使用buid.gradle让我知道

2 个答案:

答案 0 :(得分:2)

使用asynctask我已经在sdcard文件夹中下载了你可以参考的视频:

public class DounloadVideoRequestTask extends AsyncTask<String, Integer, Object> {

public static final String TAG = "DounloadVideoRequestTask";
public Context mContext;
private AsyncCallListener mAsyncCallListener;
private String mErrorMessage;
private boolean mIsError = false;

public DounloadVideoRequestTask(Context mContext) {
    this.mContext = mContext;
}

@Override
protected void onPreExecute() {
    super.onPreExecute();
}

@Override
protected Object doInBackground(String... params) {
    return storeImage(params[0], params[1], params[2]);
}

@Override
protected void onPostExecute(Object result) {
    super.onPostExecute(result);
    if (mAsyncCallListener != null) {
        if (mIsError) {
            Logger.e("", "In Asnyc call->errorMessage:" + mErrorMessage);
            mAsyncCallListener.onErrorReceived(mErrorMessage);
        } else {
            mAsyncCallListener.onResponseReceived(result);
        }
    }
}

public void setAsyncCallListener(AsyncCallListener listener) {
    this.mAsyncCallListener = listener;
}

private Object storeImage(String media, String media_type, String image_name) {
    int count;
    try {
        URL url = new URL(media);
        URLConnection conexion = url.openConnection();
        conexion.connect();
        int lenghtOfFile = conexion.getContentLength();
        String PATH = Environment.getExternalStorageDirectory() + "/Media/";
        File folder = new File(PATH);
        if (!folder.exists()) {
            folder.mkdirs();//If there is no folder it will be created.
        }

        File myFile;
        String PATH2 = "";
            PATH2 = PATH + "/Video/";
            myFile = new File(PATH2, image_name);

        if (!myFile.exists()) {
            myFile.getParentFile().mkdirs();
        }

        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream(myFile);
        byte data[] = new byte[1024];
        long total = 0;
        while ((count = input.read(data)) != -1) {
            total += count;
            publishProgress((int) (total * 100 / lenghtOfFile));
            output.write(data, 0, count);
        }
        output.flush();
        output.close();
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
        Logger.e(TAG, "Dounload Failed Exception : " + image_name);
    }

    return null;
  }
}

答案 1 :(得分:0)

您可以使用AsyncTask或Android默认DownloadManagerDownloadManager最好。  按Downloadmanager -

Download_Uri = Uri.parse("http://exaple.com/cropped-web_hi_res_512.mp4");

                DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
                request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
                request.setAllowedOverRoaming(false);
                request.setTitle("GadgetSaint Downloading " + "Sample" + ".mp4");
                request.setDescription("Downloading " + "Sample" + ".mp4");
                request.setVisibleInDownloadsUi(true);
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "/videoDir/"  + "/" + "Sample" + ".mp4");


                refid = downloadManager.enqueue(request);

当你要求图书馆时,我可以参考一下。检查这些 -

1)Android arsenal
2)PRDownloader
3)AndroidNetwroking Library