1

I have a VideoView that should start when the user click on "play button" but it doesn't work.

After some debug and some test, I see that if I start the video at the begin of the OnCreate(), it works perfect (it sets the URI).

But when I try to use the function setVideoUri inside of a Button onClickListener, it just doesn't work (it is like I don't call it).

There is no errors, or crash, just nothing happens.

Any ideas?

ImageView play2;
VideoView vView;
String video_url="URL OF THE VIDEO";
play2.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View view) 
        {
            play.setVisibility(-1);  
            publicidad.setVisibility(-1);
            principal.setVisibility(-1);
            vView.setVisibility(1);
            play2.setVisibility(-1);
            vView.requestFocus();

            String a = urls_fotos[posicion][0];
            vView.setVideoURI(Uri.parse(video_url));


            vView.setMediaController(new MediaController(ctx));


            vView.start();
            TextView ere= (TextView) findViewById(R.id.titulo);
            ere.setVisibility(-1);
            ere.setVisibility(1);
        }
    });
BenMorel
  • 34,448
  • 50
  • 182
  • 322
D4rWiNS
  • 2,585
  • 5
  • 32
  • 54

1 Answers1

1

Perhaps you are setting the listener to the wrong component?

ImageView play2;
play2.setOnClickListener(new View.OnClickListener(){
   //...
});

Code shows that you set the listener to a ImageView rather than a Button.
More over, that ImageView looks not initialized and a NullPointerException can be thrown if clicked.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • Thanks for the reply, but ImageView is initializated I just didnt put the full code, and there is no error or something – D4rWiNS Jul 09 '13 at 11:36