Question

I want to get an overview of the videos on my phone, pick one and view it in my app. I'm almost there.. just for the last bit. When i click on the video I return to my app, but the video doesn't show. What am I missing?

private static int RESULT_LOAD_VIDEO = 1;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video);

    Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

           Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("video/*");
            startActivityForResult(photoPickerIntent, RESULT_LOAD_VIDEO);

        /*     Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, RESULT_LOAD_VIDEO);*/
        }
    });
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_VIDEO && 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]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();

        VideoView imageView = (VideoView) findViewById(R.id.video1);
        imageView.setVideoPath(picturePath);

    }


}
Was it helpful?

Solution

I think you need to at least call imageView.start() to play the video (assuming you have everything else set up properly).

You can also invoke installed Android video player to play the video with just a few lines of code.

Uri fileUri = Uri.fromFile(videoFile);
  Intent intent = new Intent();
  intent.setAction(Intent.ACTION_VIEW);
  intent.setDataAndType(fileUri,                
        URLConnection.guessContentTypeFromName(fileUri.toString()));
  startActivity(intent);

Intent chooser will show up to let user pick his preferred video player. I wrote a blog to discuss how to do it in detail, http://software.intel.com/en-us/blogs/2014/03/20/video-playing-with-android-media-player. Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top