Embedded Youtube player getting cut off

家住魔仙堡 提交于 2019-12-13 01:33:37

问题


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:

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.


回答1:


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.




回答2:


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);


来源:https://stackoverflow.com/questions/14289848/embedded-youtube-player-getting-cut-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!