2014-10-08 200 views
0

我正在構建一篇閱讀TechCrunch的android應用程序的文章。Youtube視頻播放按鈕在Android視頻iframe中無效webview

在應用程序中,數據是由json排球庫對應的像id,文章,圖像和內容分析。

我在包含文本,圖像和視頻的網頁視圖中加載(html字符串)中的內容。 圖像,文本和視頻iframe在網絡視圖中正常顯示。

視頻iframe加載具有默認播放圖標的YouTube視頻,該圖標無法正常工作。

問題是,當我點擊youtube的默認播放圖標時,視頻無法播放,但當我點擊iframe區域的其餘部分時,視頻開始正​​常播放!

幫助表示讚賞。

這裏是我的代碼 -

String htmldata = "<html><head><style = text/css>  
     img{width:100%!important;height:auto!important;}iframe {width:320px;height:120px;}a { 
     color:#3366CC; text-decoration: none; }</style></head><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.setWebChromeClient(new WebChromeClient()); 
     web1.getSettings().setPluginState(PluginState.ON_DEMAND); 
     web1.loadData(htmldata,"text/html; charset=utf-8",null); 

回答

0

我認爲有與YouTube移動播放器的問題,我曾最近..但對於在這你必須讓隱藏在播放器控制一個臨時解決方案像這樣:

<iframe class="youtube-player" type="text/html" width="100%" height="338" src="http://www.youtube.com/embed/VIDEO-ID?autoplay=0&showinfo=0&controls=0" frameborder="0" allowfullscreen></iframe> 

在這種情況下,我們提出控制= 0

我希望這會有所幫助。

+0

@rhayen感謝這項工作,因爲我需要它。但現在的問題是,我得到的是存儲在我的字符串中的內容的URL,我在其他的HTML字符串中加載該字符串。所以我怎麼能添加控件= 0與我的url鏈接的iframe存儲在一個字符串變量。 – Daljeet 2014-10-08 15:19:05

相關問題