1

I want to write the code which will play a video when a button is clicked. I can't get the video to display. When I click the button to play, the emulator stops working.

public class Video extends Activity{

private static final String MOVIE_URL = "http://www.youtube.com/watch?v=XtYzTxydKmk&list=PL33CD04942E3B59AF&index=3";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_layout);

    VideoView video = (VideoView) findViewById(R.id.videoHK);
    Uri HKvideo = Uri.parse(MOVIE_URL);
    video.setMediaController(new MediaController(this));
    video.setVideoURI(HKvideo);
    video.start();
    video.requestFocus();
}

For the button I have

Button videoButton = (Button) findViewById(R.id.btnVideo);
    videoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent video = new Intent(AboutHK.this, Video.class);
            startActivity(video);
        }
    });
littledevils326
  • 689
  • 3
  • 11
  • 19

1 Answers1

1
private String MOVIE_URL = "http://www.youtube.com/watch?v=XtYzTxydKmk&list=...";

So at first when you want to play Video trough VideoView from youtube in phone, this String as Uri is not supported and it does not working. You need RTSP Link.

Here is explanation and there is guide how to convert youtube links to RTSP.

If you want to play video with classic Uri so you need to make it via Intent:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com");
startActivity(i);

But i recommend to you read

Community
  • 1
  • 1
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106