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.

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97

2 Answers2

0

I just got same type of error.

Here the problem is of Relative-Layout. Don't take Relative Layout when using Webview.

Always go for Linear-Layout. The time i changed Relative to Linear the View was Perfect.

Bhavin
  • 6,020
  • 4
  • 24
  • 26
0

You can turn off hardware acceleration and it fixes this issue for me. However, it does not play any longer on Amazon devices. I'm still looking for a fix to satisfy both issues.

webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Matthew
  • 3,411
  • 2
  • 28
  • 28