0

I'm trying to play youtube video from URL in my VideoView, but i'm getting "Can't play video error", bellow is my code, what i'm doing wrong?

public class YoutubeVideoPopUpActivity extends Activity {

    private String url;

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_youtube_video);

        final Intent intent = getIntent();
        //url = intent.getStringExtra("Url");
        url = "http://www.youtube.com/watch?v=INu_z8Zn2R8";
        setUpVideo();
    }

    private void setUpVideo() {
        videoView = (VideoView) findViewById(R.id.videoView);
        videoView.setMediaController(new MediaController(this));
        videoView.setVideoURI(Uri.parse(url));
    }

    @Override
    protected void onResume() {
        super.onResume();
        videoView.start();
    }
}
Procurares
  • 2,169
  • 4
  • 22
  • 34

2 Answers2

2

the url you are trying to use is just a normal html - page (youtube) not the actual video. this way it can't work. have a look at the official youtube api: https://developers.google.com/youtube/android/player/

or try to open the url with a new intent:

startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=Hxy8BZGQ5Jo")));

this should open the video in a webview or the installed youtube app....

malimo
  • 770
  • 6
  • 7
1

As mentioned here this could be due to:

  • Unsupported file format
  • Unsupported codecs
  • Erroneous content

and it is unlikely it is a problem with your application.

Community
  • 1
  • 1
Adam Johns
  • 35,397
  • 25
  • 123
  • 176