1

I am trying to embed youtube video in my android app using WebView. Here is the code:

{
    WebView mView = new WebView(getContext());

    String embeded = loadPlayer(); // this is javascript string containing YtPlayer api
    WebSettings webSettings = mPreview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mView.setBackgroundColor(535353);

    WebChromeClient mChromeClient = new WebChromeClient();
    mView.setWebChromeClient(mChromeClient);
    mView.setWebViewClient(new WebViewClient());
    mView.loadDataWithBaseURL("http://www.youtube.com", embeded, "text/html", "utf-8", null);
}

The problem I am having is my video gets clipped somewhere in the middle and the touch events on video don't work. Here is the link to screenshot:

enter image description here

Any ideas on what I am doing wrong here.

P.S. - This happens only on ICS 4.0.3 and it works fine on JellyBean 4.1

Any help is greatly appreciated.

4

2 回答 2

0

我刚刚遇到相同类型的错误。

这里的问题是Relative-Layout。使用 Webview 时不要采用相对布局。

总是去Linear-Layout。当我将相对于线性更改时,视图是完美的。

于 2013-04-01T12:33:38.557 回答
0

您可以关闭硬件加速,它为我解决了这个问题。但是,它不再在亚马逊设备上播放。我仍在寻找解决这两个问题的方法。

webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
于 2014-06-10T15:37:41.080 回答