Hello, I ran into a problem. WebView does not load videos. That is, the layout comes up correctly and the video in the right place. But by clicking on the video, nothing happens. Did on guides.

In the manifest:

<activity android:name=".Activities.BlogsItem" android:hardwareAccelerated="true" android:screenOrientation="portrait" > </activity> 

In the layout there are a couple of views, buttons and roughly in the center of WebView, the script comes from the server, I put an example script:

  <WebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/relative" android:layout_marginTop="5dp" /> 

In activit:

  String script = "видосвидосвидосвидосвидосвидос\n" + "<br />видос\n" + "<br />\n" + "<br />\n" + "<br /><video width=\"350.0\" controls=\"controls\"><source src=\"http://www.youtube.com/watch?v=YgmtS4n4ujY\" type=\"video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"></video>\n" + "<br />\n" + "<br />\n" + "<br />два видоса\n" + "<br />\n" + "<br /><video width=\"350.0\" controls=\"controls\"><source src=\"https://www.youtube.com/watch?v=X-4msD7eo0g\" type=\"video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"></video> <st yle>img{max-width:350.0px;!important} body{margin: 0; padding: 0}</style>"; WebView webView = (WebView) findViewById(R.id.webView); webView.setWebChromeClient(new WebChromeClient()); webView.setWebViewClient(new WebViewClient()); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setPluginState(WebSettings.PluginState.ON); webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND); webView.loadDataWithBaseURL(null, script, "text/html; charset=utf-8", "UTF-8", null); 

here is the link to the blog http://justme.webformula.pro/personal/blog/first-blog/38/

in loadDataWithBaseURL () instead of null, I visited the insert link, no use.

Who faced such a problem please help !!!

    2 answers 2

     WebView webView = (WebView) findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); String html = "<html><body>123<br> <iframe width=\"320\" height=\"315\"" + " src=\"https://www.youtube.com/embed/X-4msD7eo0g\" frameborder=\"0\" " + "allowfullscreen></iframe></body></html>"; webView.loadData(html, "text/html", "utf-8"); 

    The important point is that the video should be embed, ie the link https://www.youtube.com/embed/X-4msD7eo0g

    If webview is not important, there is such an option for https://developers.google.com/youtube/android/player/?hl=en#How_It_Works

    • Thank!!! made an embed video and now everything is fine. - Mabee Developer

    WebView is a basic engine without plug-ins. To play the video you need the appropriate plug-in that you have integrated into your application.

    In the Androyd context: https://stackoverflow.com/questions/12708890/youtube-video-not-playing-in-webview-android

    UPD: about method Shows custom (): this method is supported in API level 18. This method supports

    The solution is likely to stop working in the future.

    Here too there are code examples: https://stackoverflow.com/questions/14109083/android-webview-video-play

    UPD2: https://stackoverflow.com/questions/35223433/jwplayer6-giving-error-2035-on-firefox-for-youtube-videos - apparently, you need to put the playback not by flash but by html5 .

    UPD3: https://shashikaonline.com/2013/06/25/play-html5-video-on-android-webview/

    This is a test HTML page which has a video element.

     <!DOCTYPE html> <html> <body> <video id="video" width="320" height="240" controls> <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> </video> </body> </html> 

    Save this file in the assets folder. In the Android activity, load the url into the WebView.

     WebView mWebView = (WebView) findViewById(R.id.webView1); mWebView.setWebChromeClient(new WebChromeClient()); mWebView.loadUrl("file:///android_asset/test.html"); 

    You should get the Internet permission in the manifest file.

     <uses-permission android:name="android.permission.INTERNET"/>