Android-webview没有用webview.loaddata()加载htmlcontent

时间:2017-04-21 10:50:56

标签: android webview android-webview

我有一个使用loaddata方法加载html标签的WebView。除了视频外,所有标签都被渲染。 有人可以帮助我吗?

htmlstring="<html> <head> <link href="http://amp.azure.net/libs/amp/1.7.1/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet"> <script src="http://amp.azure.net/libs/amp/1.7.1/azuremediaplayer.min.js"></script> </head> <body> <h1>Skill Cloud</h1> <video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" tabindex="0" data-setup='{"techOrder": ["azureHtml5JS", "flashSS", "html5FairPlayHLS","silverlightSS", "html5"], "nativeControlsForTouch": false}'> </video> <script> var myOptions = { autoplay: false, controls: true, width: "100%", height: "auto", poster: "" }; var myPlayer = amp("azuremediaplayer", myOptions); myPlayer.src([{ src: "http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest", type: "application/vnd.ms-sstr+xml" }, ]); </script> <br /> <p>© Microsoft Corporation 2016</p> <video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" controls autoplay width="640" height="400" poster="" data-setup='{}' tabindex="0"> <source src="http://b028.wpc.azureedge.net/80B028/Samples/a38e6323-95e9-4f1f-9b38-75eba91704e4/5f2ce531-d508-49fb-8152-647eba422aec.ism/manifest" type="application/vnd.ms-sstr+xml" /> <p class="amp-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video</p> </video> </body> </html>" 

mWebView.loadData(htmlstring,&#34; text / html; charset = UTF-8&#34;,null);

视频源网址未呈现

1 个答案:

答案 0 :(得分:0)

你启用了javascript吗?

yourWebViewb.getSettings().setJavaScriptEnabled(true);

编辑:

我已经测试了您的代码,这样就适合我了

    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    webview.getSettings().setBuiltInZoomControls(false);
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setLoadsImagesAutomatically(true);

    webview.getSettings().setUseWideViewPort(true); 
    webview.setWebChromeClient(new WebChromeClient()); 

    String htmlstring = "<html> <head> <link href=\"http://amp.azure.net/libs/amp/1.7.1/skins/amp-default/azuremediaplayer.min.css\" rel=\"stylesheet\"> <script src=\"http://amp.azure.net/libs/amp/1.7.1/azuremediaplayer.min.js\"></script> </head> <body> <h1>Skill Cloud</h1> <video id=\"azuremediaplayer\" class=\"azuremediaplayer amp-default-skin amp-big-play-centered\" tabindex=\"0\" data-setup='{\"techOrder\": [\"azureHtml5JS\", \"flashSS\", \"html5FairPlayHLS\",\"silverlightSS\", \"html5\"], \"nativeControlsForTouch\": false}'> </video> <script> var myOptions = { autoplay: false, controls: true, width: \"100%\", height: \"auto\", poster: \"\" }; var myPlayer = amp(\"azuremediaplayer\", myOptions); myPlayer.src([{ src: \"http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest\", type: \"application/vnd.ms-sstr+xml\" }, ]); </script> <br /> <p>© Microsoft Corporation 2016</p> <video id=\"azuremediaplayer\" class=\"azuremediaplayer amp-default-skin amp-big-play-centered\" controls autoplay width=\"640\" height=\"400\" poster=\"\" data-setup='{}' tabindex=\"0\"> <source src=\"http://b028.wpc.azureedge.net/80B028/Samples/a38e6323-95e9-4f1f-9b38-75eba91704e4/5f2ce531-d508-49fb-8152-647eba422aec.ism/manifest\" type=\"application/vnd.ms-sstr+xml\" /> <p class=\"amp-no-js\">To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video</p> </video> </body> </html>";
    webview.loadDataWithBaseURL(null, htmlstring, null, "UTF-8", null);

我尝试使用&#34; loadData&#34;加载数据但不是工作而是使用&#34; loadDataWithBaseURL&#34;,试试我的代码,在android 4.2中为我工作