Reputation: 45
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?
Upvotes: 2
Views: 5525
Reputation: 13394
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
Upvotes: 1
Reputation: 31466
you need to launch an intent with a YouTube URL and let the OS handle it. That is, I don't think you can embed YouTube videos directly into your activities though I would love to be proven wrong.
Upvotes: 0
Reputation: 28103
Following snippet will hel you.
Basically you will need setOnPreparedListener
try {
final VideoView videoView =(VideoView)findViewById(R.id.videoView1);
// Set video link (mp4 format )
Uri video = Uri.parse(video_url);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.getMessage());
}
Upvotes: 0