Beni Beni - 1 month ago 22
Android Question

Why Videoview can't play a Youtube Video?

I'm trying to play a Youtube video from Youtube on some devices, but they return a dialog: "The video can't be played".

I've already read the Youtube API Documentation.

I've a VideoView and I set the video Uri as a url with a .3pg extension.

This is my code:

VideoView videoView = (VideoView)this.findViewById(R.id.video);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("rtsp://v1.cache2.c.youtube.com/CigLENy73wIaHwmhXrOROaqgpBMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp"));
videoView.requestFocus();
videoView.start();


I've tried other videos and play correctly. What am I doing wrong?

Answer

If embedding video is not your explicit requirement, Why don't you simply start an intent with the Youtube video URL and let the OS handle the intent for you ? This is the simplest possible way to play video on android as far as I know. For example,

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("Your youtube URL here"));
startActivity(intent);

For more information about Android Intents, see this link and vogella's tutorial