An_GreenDao断点续传+videoview

首先我们要集成greendao:
集成的过程不多说了,网上一大堆;
在就是建立我们的User类:
展示一下:

package com.example.greendaomoreloading;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;

/**
 * 作者:author
 * 时间 :
 * 说明:
 */
@Entity
public class User {
    @Id
    private Long id;
    private Integer thread_id;
    private Integer start_pos;
    private Integer end_pos;
    private Integer compelete_size;
    private String url;
    public String getUrl() {
        return this.url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Integer getCompelete_size() {
        return this.compelete_size;
    }
    public void setCompelete_size(Integer compelete_size) {
        this.compelete_size = compelete_size;
    }
    public Integer getEnd_pos() {
        return this.end_pos;
    }
    public void setEnd_pos(Integer end_pos) {
        this.end_pos = end_pos;
    }
    public Integer getStart_pos() {
        return this.start_pos;
    }
    public void setStart_pos(Integer start_pos) {
        this.start_pos = start_pos;
    }
    public Integer getThread_id() {
        return this.thread_id;
    }
    public void setThread_id(Integer thread_id) {
        this.thread_id = thread_id;
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @Generated(hash = 2041931179)
    public User(Long id, Integer thread_id, Integer start_pos, Integer end_pos,
            Integer compelete_size, String url) {
        this.id = id;
        this.thread_id = thread_id;
        this.start_pos = start_pos;
        this.end_pos = end_pos;
        this.compelete_size = compelete_size;
        this.url = url;
    }
    @Generated(hash = 586692638)
    public User() {
    }

}

通过greendao来实现断点的思想:
参考地址:https://www.cnblogs.com/cainiaodongdong/p/7880723.html
通过参考的文章,我们要在清单文件里面添加一些设置:
权限和name:
展示一下清单文件



    
    
    
    
    
    
        
            
                

                
            
        
    


最后我们将布局和MainActivity展示:
布局:




    

    

    

MainActivity:

package com.example.greendaomoreloading;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
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;

public class MainActivity 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_main);
        vv= (VideoView) findViewById(R.id.vv);
        total = (TextView) findViewById(R.id.textView);
        start = (Button) findViewById(R.id.start);
        pause = (Button) findViewById(R.id.delete);
        mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
        String urlString = "http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4";
        String localPath = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/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(Environment.getExternalStorageDirectory()
                        .getAbsolutePath() + "/local2/adc.mp4");
                vv.start();                
            }
        });
        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();
            }
        });


    }
}

你可能感兴趣的:(An_GreenDao断点续传+videoview)