I have a very simple WebView implementation, it works well in almost all websites, but when it comes to youtube, I can load the home page, video page, but when I click play button (on page m.youtube.com/index?desktop_uri=%2F&gl=US#/watch?v=xxxxxx), the video flash but does not play. My android version is 2.3.
first update your flash player ....
second check for permission like you have given for internet or not in androidMenifest file
third
i dont know why but webviewclient class causes the problem , we can run it in default browser remove the webviewclient class and simly load the url of youtube you will be able to run it on 2.2,2.3
w=(WebView)findViewById(R.id.webview);
w.getSettings().setJavaScriptEnabled(true);
w.getSettings().setPluginsEnabled(true);
w.loadUrl("http://www.youtube.com");
for 2.1 just add this, use intent and through parse method open it through default installed youtube application
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/v/%s")))); }
Related
I have a Android WebView app and it has YouTube videos embedded in it. I have looked all over for the answer but could not find it. Is there a way to make the YouTube app open when they look at the videos on my site? Yes I know some people don't have the YouTube app, but this is an app for a local go kart track in a small town, so I can give instructions whenever someone has a problem. :)
this is simply because you've set this as a user .
go to Settings and Applications , then , in the settings of the browser click the clear-Defaults button and it should now ask you how to open the video link.
however , if you wish to make the app to not listen to the user's settings , you can do so as well, by using "setComponent".
you could also know how to open the main activity of the app by using:
getPackageManager().getLaunchIntentForPackage(...);
I am having a problem running a HTML5 Youtube embedded in a WebView.
I want to play a Youtube video on my application. I decided to use WebView instead of VideoView, because I want to make my system more flexible to play video from web.
Although There are many ways to get play youtube on the android, but I will use the youtube embedded version. "http://www.youtube.com/embed/___________________". Because this is one of the solution I found when your android doesn't support flash.
The problem:
The WebView load as normal including the embedded Youtube. But I get a black screen on the youtube at start.
When I click on it. It load the first Image only but then It is not Playing. I tried to play on the android browser, it works smoothly but not in the webView.
Any idea why?
Below is just a snip of my code:
WebView wv = new WebView(getApplicationContext());
wv.getSettings().setPluginState(PluginState.ON);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl("http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html");
setContentView(wv);
Here are some of the resources that I found very useful:
How can we play YouTube embeded code in an Android application using webview?
play youtube video in WebView
How to embed a YouTube clip in a WebView on Android
http://apiblog.youtube.com/2010/07/new-way-to-embed-youtube-videos.html
http://www.broken-links.com/2009/10/06/building-html5-video-controls-with-javascript/
http://www.youtube.com/embed/bHQqvYy5KYo
Thank you in advance for any support and help :)
Update (13 June 2011):
I successfully load the http://m.youtube.com inside the WebView, but unable to play any video. But When I tried to load the URL on my Android Browser, it can play.
From here, I notice that the youtube site from my WebView is not signed in. So How can we allow the WebView to use the same credential as my Youtube account in my phone? Will it actually works?
Step 1 : Simply add this to Manifest file
android:hardwareAccelerated="true"
step 2 : check if you are setting layer for your webview.
(i.e.)
//myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
setting hardware acceleration to true and commenting these lines worked for me .
To know more about Hardware Acceleration and Layers look here at http://developer.android.com/guide/topics/graphics/hardware-accel.html
EDIT
So from the comment conversation we have deducted:
On this website: www.youtube.com/html5 it says you have to sign in then opt in for HTML5 video playback
That is why your video will not load, it is redirecting to a flash version and your webview does not have flash.
ORIGINAL
Are you overriding url loading so your webview is being used?
wv.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
Are you saying the video won't play but the website loads?
You could try lying to YouTube and telling them your a different browser (perhaps pretend to be the android browser) Firefox is:
wv.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.36 (KHTML, like Gecko) Chrome/13.0.766.0 Safari/534.36");
It used to be that if you clicked on an appropriate embed tag on a web page in the Android browser, it would launch the youtube app. Now that the browser has its own youtube plugin, it seems to run that instead.
How can I get the old behavior?
Youtube's web pages still have the old behavior, but I can't understand their javascript.
Thanks,
Dawg
A link like
YouTube Video
with video id does the trick. See, for example,
http://it-ride.blogspot.com/2010/04/android-youtube-intent.html
I want to call android application on clicking of button on some website from mobile.
Suppose I am opening one url on android browser and I want to call my application on clicking on button provided by that site. How to do that??
Suppose we are using browser other than Chrome then is it allowing??
If you link to your application as "myapp://foo/bar", can't you use some sort of intent filter to start your application.
I mean, if you press a youtube link in the browser it asks if you want to complete the action with the YouTube app or the browser.
I have seen similar examples regarding Google Maps links (which would open in either browser, google maps(?) or GeoBeagle).
Please take a look at the WebViewDemo. Javascript code in the web page can call into your Activity. As well as the other way around.
You cannot... if the site is being browsed in the default browser (Chrome).
If you already have an application that embeds the WebView, then you can do some bit of handling of - mouse clicks, window alerts, navigation etc. Otherwise, not!
In my android app I have a WebView to display html data from our website. Sometimes the page will have youtube embed objects. This doesn't show up properly in the app. Is there any way to show/play youtube videos in WebView ? Thanks.
You cannot show them embedded except perhaps on devices that have Flash.
However, if you can parse out the YouTube video details, you may be able to construct an ACTION_VIEW Intent that will show them on the YouTube application...for those Android devices that have the YouTube application.
You might also experiment with HTML5's <video> tag, which AFAIK is supported in the Browser application and may therefore work in WebView.
I came accross this post: link
And indeed, I basically only needed to add to the application manifest xml:
android:hardwareAccelerated="true"
And voila, even the youtube video's started playing
webView.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
// YouTube video link
if (url.startsWith("vnd.youtube:"))
{
int n = url.indexOf("?");
if (n > 0)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://www.youtube.com/v/%s", url.substring("vnd.youtube:".length(),n)));
}
return (true);
}
return (false);
}
});
You WebView (webView) will send you the shouldOverrideUrlLoading message with a URL that looks like this:
vnd.youtube:{VIDEO_ID}?{PARMS}
Parse this to convert it to http://www.youtube.com/v/{VIDEO_ID}, then hand off this revised URL as an Intent.
Works for me...
Read my post on the android-developers group here: YouTube in the emulator?
Basically, the best way to play YouTube clips is to create your own Activity for it, and here's a great example: Polish Your App: Free Embeddable Android YouTube Activity!
UPDATE: The problems with the incompatibilities due to YouTube token changes have been fixed. Latest version of the component should work just fine for public YouTube videos.
You could try switching your website to embed the HTML5 version of the YouTube player instead of the flash version. Still not sure this will work 100%, but it's obviously going to work better than the flash version on devices that don't currently support flash.
Edit: Nevermind it looks like the HTML5 version also requires the browser to support the H.264 codec, which it doesn't look like any Android devices currently support.
Embedded youtube videos work fine in desktop browsers and in iPhone browsers (even when embedded in apps on iPhone), so it seems to be problem with Android rather than YouTube.
There is a library I use for html5 video tags in the android WebView, it works for all youtube videos and most flash videos as well, supporting entering and exiting fullscreen among other features.
VideoEnabledWebView by cprcrack