2013-06-19 220 views
2
WebView wvVideo = (WebView) findViewById(R.id.wvVideo); 
    String ytVideo= "<html><body><iframe width='350' height='160' src='www.youtube.com/watch?v=yqNGzYsPN6M' frameborder='0' allowfullscreen></iframe></body></html>"; 
    wvVideo.getSettings().setPluginsEnabled(true); 
    wvVideo.getSettings().setAllowFileAccess(true); 
    wvVideo.getSettings().setPluginState(PluginState.ON); 
    wvVideo.getSettings().setBuiltInZoomControls(true); 
    wvVideo.getSettings().setJavaScriptEnabled(true); 
    wvVideo.loadData(ytVideo, "text/html", "utf-8"); 

它只是顯示縮略圖,當我點擊它時,它不會播放。只是顯示黑屏。我的API目標是15,我設置了所有必需的權限,但仍然無法正常工作。WebView未在Android中加載HTML5視頻

+0

什麼顯示在LogCat? – Raptor

+0

不,但正如我所說,它只是顯示黑屏.. – Riser

+0

@Segi試試我的答案! –

回答

0

你的設置看起來不錯。
至於我下面的設置做了我的項目,播放HTML5視頻的工作。試試看

webview.getSettings().setJavaScriptEnabled(true); 
    webview.getSettings().setDomStorageEnabled(true); // I think you will need this one 
    webview.getSettings().setPluginState(PluginState.ON); 
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);// no need I think 

    webview.getSettings().setLoadWithOverviewMode(true); 
    webview.getSettings().setUseWideViewPort(true); 
    webview.getSettings().setBuiltInZoomControls(true); 
    webview.setInitialScale(1); 

    webview.setWebChromeClient(new WebChromeClient()); // dont forget this one 

將android:hardwareAccelerated =「true」添加到您的清單文件中。

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     android:hardwareAccelerated="true"> 
+0

不能正常工作.... – Riser

+0

您是否添加了此行webview.setWebChromeClient(new WebChromeClient()); ? @Segi –

+0

是的,我做到了..但仍然是相同的.. – Riser