Ledii
Ledii

Reputation: 261

Youtube videos don't show up in WebView

I just added a webview to my app to load a simple article with a video on it and some text. The text shows up as it should but it's as if the video is not even an invisible element.

    WebView browser = (WebView) findViewById(R.id.webArticle);
    browser.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    WebSettings settings = browser.getSettings();
    settings.setBlockNetworkLoads(false);
    settings.setBlockNetworkImage(false);
    settings.setAllowContentAccess(true);
    settings.setLoadsImagesAutomatically(true);
    settings.setAllowFileAccess(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);

    browser.loadUrl(url);

Upvotes: 1

Views: 89

Answers (1)

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75778

At first ,You need to add this

getSettings().setPluginsEnabled(true);
getSettings().setUserAgent(USER_MOBILE);

Then Add to the Application Manifest File (Below Permission):

android:hardwareAccelerated="true"

For demo code Play YouTube video in WebView

play youtube video in WebView

Upvotes: 1

Related Questions