1

我是 android 的菜鸟,尽管我阅读了许多教程,但我仍然无法弄清楚如何在我的 webview 中播放 youtube 视频。我可以毫无问题地浏览该网站,但是当我点击视频时,什么也没有发生。我尝试将 android:hardwareAccelerated="true" 添加到我的清单中,但没有成功。任何帮助是极大的赞赏。这是我到目前为止所拥有的:

  huffingtonpost = (WebView)findViewById(R.id.webView1);
    huffingtonpost.setWebViewClient(new WebViewClient());
    huffingtonpost.getSettings().setJavaScriptEnabled(true);
    huffingtonpost.getSettings().setPluginState(PluginState.ON);
    huffingtonpost.getSettings().setUseWideViewPort(true);
    huffingtonpost.getSettings().setLoadWithOverviewMode(true);

    try{
    huffingtonpost.loadUrl("http://www.youtube.com/KitcoNews");
    }catch (Exception e){
        e.printStackTrace();
    } 

我的清单

 <application
    android:hardwareAccelerated="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
4

2 回答 2

0

如何在 android webview 中播放 Youtube 频道?

公共类 MainActivity 扩展 Activity {

   @Override
     public void onCreate(Bundle savedInstanceState) {

          super.onCreate(savedInstanceState);

          //setContentView(R.layout.main);

        String html="http://www.youtube.com/KitcoNews";
          // Let's display the progress in the activity title bar, like the
          // browser app does.
          getWindow().requestFeature(Window.FEATURE_PROGRESS);

          WebView webview = new WebView(this);
          setContentView(webview);

          webview.getSettings().setJavaScriptEnabled(true);

          final Activity activity = this;
          webview.setWebChromeClient(new WebChromeClient() {
          public void onProgressChanged(WebView view, int progress) {

             activity.setTitle("Loading...");
                activity.setProgress(progress * 100);

                if(progress == 100)
                    activity.setTitle(""Done);

          }
        });


webview.setWebViewClient(new WebViewClient() {

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
          //Users will be notified in case there's an error (i.e. no internet connection)
          Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
 });
       //This will load the webpage that we want to see
        webview.loadUrl(html);

     }
    }
于 2013-07-02T08:53:38.587 回答
0

这是一个代码示例:

myWebView = (WebView) findViewById( R.id.webview_compontent );

String playVideo= "<html><body>Youtube video .. <br> <iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/bIPcobKMB94\" frameborder=\"0\"></body></html>"

myWebView.loadData(playVideo, "text/html", "utf-8");

如果 URL 是从 EditText 或其他东西中获取的,您可以只操作字符串playVideo

希望这可以帮助。

于 2012-09-25T09:53:19.760 回答