Pergunta

I'm attempting to play a video after launching the gallery however I am never prompted to choose an app to play with - and the video never plays - how might I edit this code to get the video to play?

Source:

ImageButton vb = (ImageButton) findViewById(R.id.video);
        vb.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(UI.this, "Video Testimonial", Toast.LENGTH_LONG)
                        .show();
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("video/*");
                startActivityForResult(photoPickerIntent, SELECT_VIDEO);

            }
        });
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {
            if (resultCode == Activity.RESULT_OK) {
                Uri selectedVideo = data.getData();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(selectedVideo, "video/*");
                startActivity(Intent.createChooser(intent,
                        "Complete action using"));  

            }

        }

P.S.

If I close my app, open the gallery from the launcher, and click a video it plays - however when I do the same from the gallery displayed using the code below - no video is ever played.

Foi útil?

Solução

Can you please make sure if the value of SELECT_VIDEO is 1 as

in this line you are checking requestCode with 1 if (requestCode == 1)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top