SamiunNafis
SamiunNafis

Reputation: 149

Youtube videos does not loads in WebView

I created a WebView for YouTube . The URL loads but the videos does not loads.

WebView web = (WebView) findViewById(R.id.web);
web.loadUrl("http://youtube.com");

Edited:

That problem is now fixed after setting WebChromeClient.

web.setWebChromeClient(new ChromeClient());

Create a new class which extends WebChromeClient

public class ChromeClient extends WebChromeClient{

}

Upvotes: 2

Views: 69

Answers (2)

Treewallie
Treewallie

Reputation: 356

The url needs HTTPS not HTTP in order for it to load properly.

https://www.youtube.com/

Upvotes: 0

Azeem Iqbal
Azeem Iqbal

Reputation: 61

As I found that YouTube is working in default browser used. this workaround to get it working

You have to check first, try the code below

if (url.contains("youtube")) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} else {
    webView.loadUrl(url);
}

hope, it helps

Upvotes: 3

Related Questions