2013-03-11 48 views
1

我想要寫的代碼在單擊按鈕時將播放視頻。我無法看到要顯示的視頻。當我點擊按鈕播放時,模擬器停止工作。的Android VideoView不工作

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); 
     } 
    }); 

回答

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

所以剛開始的時候,你想在手機從YouTube播放視頻低谷VideoView,這個字符串爲Uri不支持,它不工作。您需要RTSP鏈接

這裏是explanation且有指導how to convert youtube links to RTSP

如果你想與經典Uri播放視頻,所以你需要通過Intent使它:

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

但我建議你閱讀