package com.example.administrator.zmlx_3; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.VideoView; import com.example.administrator.zmlx_3.SSPP.DownloadUtil; public class NewActivity extends AppCompatActivity { private static final String TAG = MainActivity.class.getSimpleName(); private ProgressBar mProgressBar; private Button start; private Button pause; private TextView total; private int max; private DownloadUtil mDownloadUtil; private VideoView vv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new); total = (TextView) findViewById(R.id.textView); start = (Button) findViewById(R.id.start); pause = (Button) findViewById(R.id.delete); vv = (VideoView) findViewById(R.id.vv); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); Intent in=getIntent(); String path=in.getStringExtra("path"); String urlString =path; String localPath =getCacheDir() + "/local2"; mDownloadUtil = new DownloadUtil(2, localPath, "adc.mp4", urlString, this); mDownloadUtil.setOnDownloadListener(new DownloadUtil.OnDownloadListener() { @Override public void downloadStart(int fileSize) { // TODO Auto-generated method stub Log.w(TAG, "fileSize::" + fileSize); max = fileSize; mProgressBar.setMax(fileSize); } @Override public void downloadProgress(int downloadedSize) { // TODO Auto-generated method stub Log.w(TAG, "Compelete::" + downloadedSize); mProgressBar.setProgress(downloadedSize); total.setText((int) downloadedSize * 100 / max + "%"); } //下载完成 @Override public void downloadEnd() { vv.setVideoPath(getCacheDir() + "/local2/adc.mp4"); vv.start(); Log.w(TAG, "ENd"); } }); start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mDownloadUtil.start(); } }); pause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mDownloadUtil.pause(); } }); } }
多线程下载
最新推荐文章于 2023-10-15 11:16:48 发布