2012-08-13 328 views
2

在我的應用程序有一個videoview,我想在that.For播放YouTube視頻,我試過很多方法,如播放YouTube視頻的videoview

VideoView mVideoView = new VideoView(this); 
setContentView(mVideoView); 
mVideoView.setVideoURI(Uri.parse("rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp")); 
mVideoView.start(); 

對於這個我得到

08-13 12:33:07.443: D/MediaPlayer(618): Couldn't open file on client side, trying server side 
08-13 12:33:09.003: E/MediaPlayer(618): error (1, -2147483648) 
08-13 12:33:09.003: E/MediaPlayer(618): Error (1,-2147483648) 

然後我試圖

VideoView mVideoView = new VideoView(this); 
setContentView(mVideoView); 
mVideoView.setVideoURI(Uri.parse("vnd.youtube:GDD0Brw-udk")); 
mVideoView.start(); 

這裏也是我收到了同樣的錯誤。

而且

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=GDD0Brw-udk&feature=youtube_gdata_player"))); 

這讓我的應用程序,並開始移動版YouTube,我無法控制。

我用另一種方法是

Intent lVideoIntent = new Intent(null, Uri.parse("http://www.youtube.com/get_video_info?&video_id=GDD0Brw-udk") 
      , this, IntroVideoActivity.class); 
startActivity(lVideoIntent); 

這也是不是爲我工作..

我應該怎麼do..Anyone幫我please..Thanx提前

+0

duplicate http://stackoverflow.com/questions/3815090/webview-and-html5-video – jenuine 2012-08-13 07:37:39

回答

0

如果您希望你可以把它放到webview中。這是我得到它的工作:

    webview = (WebView) v.findViewById(R.id.videoview); 
        String videoPoP = "http://www.youtube.com/v/A6kCkkLo6Rw?"; 
     webview.setHorizontalScrollBarEnabled(false); 
     webview.setVerticalScrollBarEnabled(false); 
     webview.getSettings().setJavaScriptEnabled(true); 
     webview.getSettings().setPluginState(PluginState.ON); 


      String widthAndHeight = "width=\"" + widthdp + "\" height=\"" + heightdp + "\"";   

     temp = "<object " 
       + widthAndHeight 
       + ">" 
       + "<body style='margin:0;padding:0;'>" 
       + "<param name='allowFullScreen' value='false'>" 
       + "</param><param name='allowscriptaccess' value='always'>" 
       + "</param><embed src='" 
       + videoPoP 
       + "'" 
       + " type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true'" 
       + widthAndHeight + "></embed></object>"; 

     webview.loadData(temp, "text/html", "utf-8"); 

傳遞參數的寬度和高度(靜態或動態高達你)的widthdp和heightdp變量中,並把它放在一個WebViewClient,它應該正常工作

0

代碼:

VideoView mVideoView = new VideoView(this); 
setContentView(mVideoView); 
mVideoView.setVideoURI(Uri.parse("rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp")); 
mVideoView.start(); 

是罰款,將工作對我來說只是檢查您的網址。