【问题标题】:Android-webview not loading htmlcontent with webview.loaddata()Android-webview 不使用 webview.loaddata() 加载 htmlcontent
【发布时间】:2017-09-18 08:14:58
【问题描述】:

我有一个使用 loaddata 方法加载 html 标签的 WebView。除了 videourl 之外,所有标签都被渲染。 有人能帮帮我吗?

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, "text/html; charset=UTF-8", null);

视频源网址未呈现

【问题讨论】:

    标签: android webview android-webview


    【解决方案1】:

    您启用了 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);
    

    我尝试使用“loadData”加载数据,但无法使用“loadDataWithBaseURL”代替,试试我的代码,在 android 4.2 中对我有用

    【讨论】:

    • 我启用了 setjavascript 除了这个 im 使用以下 webview 设置 setRenderPriority(WebSettings.RenderPriority.HIGH); s.setBuiltInZoomControls(false); s.setLoadWithOverviewMode(true); s.setLoadsImagesAutomatically(true); s.setJavaScriptEnabled(true);
    • webview.loadurl() 工作正常,但问题在于加载该页面的 html 标签
    • 看看我的编辑。我不知道这是否正确,但它对我有用。
    • 我在版本 5+ 的设备中使用了相同的代码,我只能看到一些灰色的播放按钮,并且视频没有播放。
    猜你喜欢
    • 2019-10-21
    • 1970-01-01
    • 2011-10-08
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2015-06-16
    • 2018-10-18
    • 2017-02-21
    相关资源
    最近更新 更多