1

我有一个使用 WebView 显示网页的活动。在该页面中,有一个指向 YouTube 视频的链接(因此它不是我可以或需要嵌入的视频)。

问题是视频无法播放 - 我可以看到带有单击图标的视频预览图像,但单击它没有响应。有什么可以做的吗?

public class DisplayWebPage extends Activity
{   
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display_web_page);

        Bundle extras = getIntent().getExtras();
        String url = extras.getString("url");
        WebView webview = (WebView)findViewById(R.id.WebView1);

        webview.setWebViewClient(new WebViewClient());
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);
    }
}
4

1 回答 1

5
public class MyPdfViewActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView mWebView=new WebView(MyPdfViewActivity.this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.loadUrl(youtube_link);
    setContentView(mWebView);
  }
}

更新:: 如果上述方法不起作用,请尝试以下方法::

public class main extends Activity {
    /** Called when the activity is first created. */
     @ Override


     public void onCreate (Bundle savedInstanceState) {
         super. onCreate (savedInstanceState);



         setContentView (R.layout.main);

         WebView web = (WebView) findViewById (R.id.webView);
         web. getSettings().setJavaScriptEnabled (true); 
         web. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
         web. getSettings().setPluginsEnabled (true);
         web. getSettings().setSupportMultipleWindows (false);
         web. getSettings().setSupportZoom (false);
         web. setVerticalScrollBarEnabled (false);
         web. setHorizontalScrollBarEnabled (false);


         web. loadUrl ("THE URL TO YOUR WEBVIEW SITE SHOULD GO HERE");

         web. setWebViewClient (new WebViewClient () {
             @ Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
             if (url.startsWith("vnd.youtube")){

             startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));

             return true;
             }
             else
             {
             return false;
             }
             }
         });
     }

 } 
于 2012-06-02T09:59:49.917 回答