Prasham
Prasham

Reputation: 6686

Android Mediaplayer throws an error while playing a youtube video with video view

Here is the code for playing a url with vedio view

String urlVideo = "http://www.youtube.com/cp/vjVQa1PpcFPLrLo9hkR90zKx_XHP5kMNaNb-_bE3v0s=";
    VideoView video = (VideoView) findViewById(R.id.videoView1);
    Log.d("You", urlVideo);
    video.setVideoURI(Uri.parse(urlVideo));
    MediaController mc = new MediaController(this);
    video.setMediaController(mc);
    video.requestFocus();
    video.start();
    mc.show();

It throws error and can not start the video

Here is the logcat message

 ERROR/MediaPlayer(1765): error (1, -2147483648)

ERROR/MediaPlayer(1765): Error (1,-2147483648) DEBUG/VideoView(1765): Error: 1,-2147483648

  1. The simulator and target OS is 2.2.
  2. This is tested on simulator.

Can this code run properly on device?? Can you explain the error code and reason behind the error??

Edit : Well thanks all for your suggesions. Actually my application needs to play a video in its own design and according to your suggesions and some other post I have seen on web it can be concluded that it can not be played on the way I desire and I have to open it in a web view. Thanks...

Upvotes: 1

Views: 4748

Answers (1)

devunwired
devunwired

Reputation: 63303

The exact error code is MEDIA_ERROR_UNKNOWN (Unknown error...very helpful here).

The reason it is failing is the link you are using goes directly to a Flash video. Flash is not supported in VideoView, as Dianne so succinctly puts in this post...

The best way for you to show that video is probably to package it up in an Intent and let either the Browser or the YouTube app play it. If the user has some other Flash-enabled app like Skyfire, it should show up in the choices as well. However, this usually only works with the watch link for a video, so http://www.youtube.com/watch?v=fX_wt7cPCU4 in your case.

String videoUrl = "http://www.youtube.com/watch?v=fX_wt7cPCU4";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(videoUrl));
startActivity(Intent.createChooser(intent, "Play Video Using");

On a device with the YouTube app installed this will come up as an option, although not all YouTube videos can play in the mobile app for some reason.

Hope that helps!

Upvotes: 5

Related Questions