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

被刻印的时光 ゝ 提交于 2019-12-11 14:00:39

问题


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...


回答1:


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!



来源:https://stackoverflow.com/questions/4880379/android-mediaplayer-throws-an-error-while-playing-a-youtube-video-with-video-vie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!