2011-07-23 59 views
1

無法顯示視頻我要上的WebView的YouTube播放視頻的Android的WebView ..它顯示視頻,但我想發揮它在同一頁我的意思是我使用WebViewClient上 ..但使用它不播放視頻..(在按播放按鈕它不播放視頻)我該怎麼辦?我的代碼是
使用WebViewClient

setContentView(R.layout.main); 
      wvSpecials = (WebView) findViewById(R.id.webView1); 
      WebSettings webSettings = wvSpecials.getSettings(); 
      webSettings.setJavaScriptEnabled(true); 
      wvSpecials.loadUrl("http://here.com/is link/"); 
      wvSpecials.setWebViewClient(new WebViewClient() { 
       ProgressDialog progressDialog = new ProgressDialog(
         specialsActivity.this); 
       @Override 
       public void onPageStarted(WebView view, String url, Bitmap favicon) { 
        progressDialog.setMessage("Please wait..."); 
        progressDialog.show(); 
        super.onPageStarted(view, url, favicon); 
       } 

       @Override 
       public void onPageFinished(WebView view, String url) { 
        if (progressDialog.isShowing()) { 
         progressDialog.dismiss(); 
        } 
        super.onPageFinished(view, url); 
       } 
       @Override 
       public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        view.loadUrl(url); 

        return super.shouldOverrideUrlLoading(view, url); 
       } 

      }); 
} 

回答

3

您可以使用如下代碼:

public class YouTube extends Activity{ 

    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
     WebView myWebView; 
     myWebView = (WebView) findViewById(R.id.web); 
     myWebView.setWebViewClient(new MyWebViewClient()); 
    String pre="<iframe class=youtube-player type=text/html width="; 
    String height=" height="; 
    String suffix=" src=http://www.youtube.com/embed/**xxxxxxxxxxx**?autoplay=1 frameborder=0>"; // replace xxxxxxxxxxx with the specific embed id of your video 
     String playVideo=pre+260+height+150+suffix; 
     myWebView.getSettings().setPluginsEnabled(true); 
     myWebView.getSettings().setJavaScriptEnabled(true); 
    myWebView.loadData(playVideo,"text/html","UTF-8"); 
} 
// override default behaviour of the browser 

private class MyWebViewClient extends WebViewClient { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 


     ProgressDialog dialog = ProgressDialog.show(getApplicationContext(), "", 
       "Loading. Please wait...", true); 
     @Override 
      public void onPageFinished(WebView view, String url) { 
      dialog.dismiss(); 
      } 


    } } 
相關問題