Android视频选择器

第一步:导入依赖

 implementation 'com.github.LuckSiege.PictureSelector:picture_library:v2.6.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'    //图片加载框架
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'    //图片加载框架注解处理器

implementation 'cn.jzvd:jiaozivideoplayer:7.3.0'

第二步:添加权限

   



第三步:添加镜像

allprojects {
repositories {
    google()
    jcenter()
    maven { url 'https://jitpack.io' }
}
}

MainAcivity的完整代码:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private final static int FLAG_REQUEST_CAMERA_VIDEO = 2;
private List selectList;
private String video_path;

private View add_view;

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    PermissionMgr.getInstance().onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PermissionMgr.getInstance().requestPermissions(this);

    initView();
}

private void initView() {

    add_view = findViewById(R.id.add);
    add_view.setOnClickListener(this);

}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.add:
            doPickImageFromSystem();
            break;
    }
}

private void doPickImageFromSystem() {
    PictureSelector.create(this)
            .openGallery(PictureMimeType.ofVideo())
            .maxVideoSelectNum(1)
            .loadImageEngine(GlideEngine.createGlideEngine()) // 请参考Demo GlideEngine.java
            .forResult(PictureConfig.CHOOSE_REQUEST);


}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
            case PictureConfig.CHOOSE_REQUEST:
                // 结果回调
                selectList = PictureSelector.obtainMultipleResult(data);

                Log.d("TAG", "onActivityResult: " + selectList.get(0).getRealPath());
                video_path = selectList.get(0).getRealPath();

                add_view.setVisibility(View.GONE);

                doDisplay();
                break;
            default:
                break;
        }
    }
}

private void doDisplay() {

    JzvdStd jzvdStd = (JzvdStd) findViewById(R.id.videoplayer);
    jzvdStd.setUp(video_path
            , "饺子闭眼睛");
    jzvdStd.posterImageView.setImageResource(R.drawable.ic_launcher_background);

 }

}

GitHub地址:https://github.com/LuckSiege/PictureSelector

你可能感兴趣的:(Android视频选择器)