-1

I am building an article reading android application like TechCrunch.

In the application, the data is parsed by json volley like id, article, images and content.

I am loading content html string in webview which contains text,images and videos.

Text,images and video iframe are displaying fine, but I click on any video, nothing happens.

This is my iframe code in html content:

This is my code:

String htmldata = "<html><style = text/css>       
 img{width:100%!important;height:auto!important;}iframe, .video-container object, .video-
container embed {max-width:100%;max-height:100%;}a { color:#3366CC; text-decoration: none; }
 </style><body style = line-height:25px; >"+c+"</body></html>";               


       web1 = (WebView) findViewById(R.id.webView2);                
            web1.setWebViewClient(new myWebClient());
            web1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            web1.getSettings().setJavaScriptEnabled(true); 
            //web1.getSettings().setJavaScriptEnabled(true);
            //web1.setInitialScale(65);
            web1.getSettings().setDefaultFontSize(18);           
            //web1.loadUrl(htmldata);
            web1.loadData(htmldata,"text/html; charset=utf-8",null);
Hitesh Matnani
  • 533
  • 2
  • 8
  • 26

2 Answers2

3

Try:

        web1 = (WebView) findViewById(R.id.webView2);                
        web1.setWebViewClient(new myWebClient());
        web1.setWebChromeClient(new WebChromeClient());
        web1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        web1.getSettings().setJavaScriptEnabled(true); 
        web1.getSettings().setPluginState(PluginState.ON);
        web1.getSettings().setDefaultFontSize(18);           
        web1.loadData(htmldata,"text/html; charset=utf-8",null);

For more check: Android webview cannot render youtube video embedded via iframe

Community
  • 1
  • 1
sjain
  • 23,126
  • 28
  • 107
  • 185
  • Thanks for reply! its giving error - WebSettings cannot be resolved to a variable – Hitesh Matnani Oct 07 '14 at 13:59
  • now is giving a warring The method setPluginState(WebSettings.PluginState) from the type WebSettings is deprecated – Hitesh Matnani Oct 07 '14 at 14:07
  • 1
    yes the future support with plugin will not be available. Its to check if it works. Also, did you checked if hardware acceleration turned on in your manifest using `android:hardwareAccelerated="true"` ? – sjain Oct 07 '14 at 14:18
  • Are you seeing black screen when you play a youtube video ? – sjain Oct 07 '14 at 14:31
  • yes i am seeing a proper image of video and there is a play button also arrive there but when i click it my video does not play black screen come there – Hitesh Matnani Oct 07 '14 at 14:35
  • Just a known issue - Your android device probably needs flash to make it work. That code works on android 4.0 or newer. All you need to do is check the sdk version. If 4.0 or newer, play it on webview if not, use youtube intent. – sjain Oct 07 '14 at 14:36
  • i am checking in my phone and it is 4.1 still it dose not support my video – Hitesh Matnani Oct 07 '14 at 14:40
  • Did you tried adding `web1.setWebChromeClient(new WebChromeClient());` ? – sjain Oct 07 '14 at 14:41
  • The video iframe load youtube video that has a default play icon which is not working properly. The problem is that when I click on that default play icon of youtube the video dose not play, But when I click rest of the area of iframe the video start playing properly! – Hitesh Matnani Oct 08 '14 at 08:36
0

Did you see this Android. WebView and loadData

Community
  • 1
  • 1
  • Hey! Thanks sudheer chowdary I am loading data by parsing and it content data like text, images and video means in i have to load data in web.loaddata not in web.loadurl can you please describe other method if you know how to fix this ? – Hitesh Matnani Oct 07 '14 at 14:11
  • I am doing like this only and all my content are being displaying fine but i have problem with my ifram of video they are no playing in web-view – Hitesh Matnani Oct 07 '14 at 14:17
  • i think its not possible. other wise you can convert youtube URL to gdata url then you need to play that url on VideoView or use directly youtube api – Sudheer Chowdary Sirimalla Oct 07 '14 at 14:35
  • you mean to say i use youtube api to play my video ? how could i do this – Hitesh Matnani Oct 07 '14 at 14:38