Embedded Youtube player getting cut off - android

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.

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.

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

Related

can any one tell me that we can open a link in webview to play a video

my probelm is how to play a video in a webview. i can setup a live french on 000webhost to stream in android.now the problem is how can i play in android using a webview... here is my code which can display a white screen i dont know why
mWebView = (WebView) findViewById( R.id.webView1 ); //This is the id you gave
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true); //Zoom Control on web (You don't need this
//if ROM supports Multi-Touch
mWebView.getSettings().setBuiltInZoomControls(true); //Enable Multitouch if supported by ROM
// Load URL
mWebView.loadUrl("http://gumsuminnocent.host56.com/frenchchannel.html");
not working just white screen.
plz help me and Thanks in advance
sorry for my poor english
Use Webview, Create a string for html tags, add iframe tage and pass the height and width of the video and url. and load the string in webview
webView.loadData(strHTMLTags, "text/html", "UTF-8");

Video not appearing on a WebView

I has a app that loads a url on a WebView.
web = (WebView) findViewById(R.id.webview);
WebSettings settings = web.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
settings.setSupportMultipleWindows(false);
settings.setSupportZoom(false);
settings.setPluginsEnabled(true);
web.setVerticalScrollBarEnabled(false);
web.setHorizontalScrollBarEnabled(false);
web.loadUrl(lastUrl);
But a spot that should has Video first shows a "loading" view than disappears, if a tap on it occurs, the sound of the video starts playing but not show.
PS: I came across answers that told to add the hardwareAccelerated flag on Manifest, but this solutions simply does not work here.
I used settings.setDomStorageEnabled(true) as well with hardwareAccelerated="true" and it's working.
Did you see this question and the comment from slytron?
By the way setPluginsEnabled is deprecated in favor of setPluginState as of API level 8.

Android +1 button in WebView

I've tried putting Google's +1 button in WebView using the methods they describe. I've initialized the WebView as follows:
final WebView web = (WebView)findViewById(R.id.webView);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setSavePassword(false);
web.getSettings().setBuiltInZoomControls(false);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setLoadWithOverviewMode(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setHorizontalScrollBarEnabled(false);
web.setBackgroundColor(0xff2e2e2e);
web.loadDataWithBaseURL(null, htmlCodeGoesHere, "text/html", "utf-8", null);
And the html code:
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone href="http://stackoverflow.com"></g:plusone>
The problem is... the button doesn't display at all.
How do I fix it? By the way - I also want the button to launch a new window instead using the WebView. Is there a simple solution?
Thanks
The problem lies in permissions system in WebView. Scripts in local files have problems accessing external resources. The solution is to make WebView think local code was loaded from external website.
web.loadDataWithBaseURL("http://fake.com", htmlCodeGoesHere, "text/html", "utf-8", null);
The button will appear, but unfortunetely it doesn't work well in WebView.
I am not too experienced with WebView, but the fact the the button doesn't show up at all, sounds like it could be an issue in your layout/main.xml file. Have you taken a look at this yet?
Also, for the button to launch a new window, I think it is possible to attach an setOnClickListener, once that is done just treat it as a button, and open a new window. I hope that is possible.

zoom controller not working in webview in android

I am suffering from a strange problem in order to implement WebView in android. I am trying to load html5 supported web page in my WebView, but the problem is default zoom controller is not working in WebView.
i tried with the following code.
webview.getSettings().setBuiltInZoomControls(true);
webview.invokeZoomPicker();
Can any body help regarding this.
Add this line also
WebSettings setting = wView.getSettings();
setting.setBuiltInZoomControls(true);
setting.setSupportZoom(true);
if work or not please reply

WebView Problem on Youtube site in Android?

i tried to load the url ww.youtube.com on my app in a webview. but it cant be load completely. it loads just like below image. in the browser it loads comfortably. why? Any Idea?
image http://www.freeimagehosting.net/uploads/d7356dd8e1.png
the simple answer is to call the youtube app thats loaded on every phone with your webview. check out the code on http://fluxkore.com/index.php/android-apps/ to call the youtube app.....
Enable JavaScript! =)
myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("http://www.youtube.com");
It might be a problem with WebViews - WebViews aren't fully fledged browsers, and have limited functionality. For example, the reference page specifically says that WebViews don't handle JavaScripts. If JavaScripts, Flash or something like that is required to properly load YouTube, then that could be why the WebView doesn't handle it properly.

Categories

Resources