Android从相册选取视频

1.

/**
 * 从相册中选择视频
 */
private void choiceVideo() {
    Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, 66);
}

2.

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 66 && resultCode == RESULT_OK && null != data) {
        Uri selectedVideo = data.getData();
        String[] filePathColumn = {MediaStore.Video.Media.DATA};

        Cursor cursor = getContentResolver().query(selectedVideo,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        VIDEOPATH = cursor.getString(columnIndex);
        cursor.close();
        submit_vd_ad.setText(VIDEOPATH);
    }
    if (resultCode != Activity.RESULT_OK) {
        return;
    }
}
posted @ 2018-11-24 12:33  黑帅-quan  阅读(7262)  评论(0编辑  收藏  举报