使用任何路径(内部或外部)ANDROID从库中播放视频视图

时间:2015-08-17 12:25:33

标签: java android

我尝试了这段代码:

1-初始化

private static final int PICK_FROM_GALLERY = 1;
VideoView video;

2- onCreate Methos

video = (VideoView) findViewById(R.id.VideoID);

3- onClick(实现OnClickListener)

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.VideoID:
            Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(galleryIntent, PICK_FROM_GALLERY);
        break;
        }
    }

4- onActivityResult方法

if (requestCode == PICK_FROM_GALLERY) {
                Uri uri = data.getData();
                video.setVideoURI(uri);
                video.requestFocus();
                video.start();
            }

Galaxy Note 3上的输出: 1-作为Toa​​st:

data: Intent { dat=content://media/external/video/media/8899 (has extras) } 

2-作为消息对话框:

Can't play this video

我想通过任何路径(内部或外部路径)从(图库或任何地方)播放视频视图

0 个答案:

没有答案