问题
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