2013-02-08 66 views
1

我想告訴你在Android的低版本和更高版本管視頻。我的代碼工作正常到Android 3.0但4.0上顯示你管視頻屏幕,但是當點擊播放它只顯示你管視頻上的進度條。webview不顯示你管視頻上的Android 4.0(ICS)

這裏是我的代碼 -

if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) 
     { 
      playVideoForBelowVersion(); 
     } 

     else 
     { 

      playVideoForIcs(); 
     } 
private void playVideoForBelowVersion() 
    { 
     String url = videoLinks[position] + "?autoplay=1"; 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView. getSettings().setJavaScriptCanOpenWindowsAutomatically (false); 
     webView. getSettings().setPluginsEnabled (true); 
     webView. getSettings().setSupportMultipleWindows (false); 
     webView. getSettings().setSupportZoom (false); 
     webView. setVerticalScrollBarEnabled (false); 
     webView. setHorizontalScrollBarEnabled (false); 
     webView.loadUrl(url); 
     webView.setWebChromeClient(new WebChromeClient()); 
     webView.setWebViewClient(new WebViewClient() 
     { 


      @Override 
      public void onPageFinished(WebView view, String url) { 
       // TODO Auto-generated method stub 
       super.onPageFinished(view, url); 
//    progressDialog.dismiss(); 

      } 

      @Override 
      public void onPageStarted(WebView view, String url, Bitmap favicon) { 
       // TODO Auto-generated method stub 
       super.onPageStarted(view, url, favicon); 
       /*progressDialog.setMessage("Loading Video please wait..."); 
       progressDialog.show();*/ 


      } 

      @Override 
      public void onReceivedError(WebView view, int errorCode, 
        String description, String failingUrl) { 
       // TODO Auto-generated method stub 
       super.onReceivedError(view, errorCode, description, failingUrl); 
       Utilities.showToast(FullVideoAct.this, "Video Error..."); 
      } 

      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       // TODO Auto-generated method stub 
       view.loadUrl(url); 
       return true; 
      } 

     }); 
     webView.requestFocus(); 
    } 

    private void playVideoForIcs() 
    { 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); 
     String strUrl = "http://m.youtube.com/index?&desktop_uri=%2F#/watch?v="+videoLinksIds[position]; 
//  String strUrl = videoLinks[position] + "?autoplay=1"; 
//  String strUrl ="http://www.youtube.com/v/"+videoLinksIds[position]+"?enablejsapi=1&version=3&playerapiid=ytplayer"; 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView. getSettings().setJavaScriptCanOpenWindowsAutomatically (false); 
     webView. getSettings().setPluginsEnabled (true); 
     webView. getSettings().setSupportMultipleWindows (false); 
     webView. getSettings().setSupportZoom (false); 
     webView. setVerticalScrollBarEnabled (false); 
     webView. setHorizontalScrollBarEnabled (false); 
     webView.loadUrl(strUrl); 
     //wvVideo.loadData(htmlString, "text/html", "UTF-8"); 
     webView.setWebChromeClient(new WebChromeClient()); 

     webView.requestFocus(); 

    } 
+0

你爲什麼使用webview? (https://developers.google.com/youtube/android/player/) – Budius

+0

@budius,哪些是其他選項? –

+0

我發佈的鏈接! – Budius

回答

2

在Android清單文件中設置的android:硬件加速= 「真」,在這樣的 應用Android應用程序標籤:圖標= 「@繪製/ ic_launcher」 機器人:硬件加速= 「true」 android:label =「@ string/app_name」

+0

感謝它的工作......我已經使用該屬性,但由於錯誤,我將其設置爲false。 –

+0

你好Pankaj,如果我的回答滿意你請投票給我:) – AndroidEnthusiastic