1

我想编写在单击按钮时播放视频的代码。我无法显示视频。当我单击按钮播放时,模拟器停止工作。

public class Video extends Activity{

private static final String MOVIE_URL = "http://www.youtube.com/watch?v=XtYzTxydKmk&list=PL33CD04942E3B59AF&index=3";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_layout);

    VideoView video = (VideoView) findViewById(R.id.videoHK);
    Uri HKvideo = Uri.parse(MOVIE_URL);
    video.setMediaController(new MediaController(this));
    video.setVideoURI(HKvideo);
    video.start();
    video.requestFocus();
}

对于我有的按钮

Button videoButton = (Button) findViewById(R.id.btnVideo);
    videoButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent video = new Intent(AboutHK.this, Video.class);
            startActivity(video);
        }
    });
4

1 回答 1

1
private String MOVIE_URL = "http://www.youtube.com/watch?v=XtYzTxydKmk&list=...";

So at first when you want to play Video trough VideoView from youtube in phone, this String as Uri is not supported and it does not working. You need RTSP Link.

Here is explanation and there is guide how to convert youtube links to RTSP.

If you want to play video with classic Uri so you need to make it via Intent:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com");
startActivity(i);

But i recommend to you read

于 2013-03-11T21:16:41.727 回答