【问题标题】:load html media like video, audio and pdf from url in android从android中的url加载html媒体,如视频、音频和pdf
【发布时间】:2018-05-31 11:14:24
【问题描述】:

我正在开发 android 应用程序,从服务器加载不同的媒体类型,媒体以 html 格式出现,如下所示:

          {
    "messages_PK_ID": 390,
    "messages_Name": "المنهج التأسيسي1/ الفصل الثاني عشر/ منعطفات الوعي",
    "messages_ToSendDateDiff": 330,
    "message_URL": " <div>\r\n        <table dir=\"rtl\">\r\n            <tbody>\r\n                <tr>\r\n                    <td>\r\n                        <table id=\"table1\" dir=\"rtl\">\r\n                            <tbody>\r\n                                 <tr>\r\n                                    <td>\r\n                                        <p style=\"text-align: center; font-size: x-large; font-weight: bold\">\r\n                                            <a href=\"http://iacademypd.com/ViewVideos.aspx?id=vihVoSHf%2brFvvGg8GY25%2bQ%3d%3d\">إذا واجهتك مشكلة في فتح المواد ... الرجاء الضغط هنا \r\n                                            </a>\r\n                                        </p>\r\n                                        <p style=\"text-align: center; font-size: x-large; font-weight: bold\">\r\n                                            &nbsp;</p>\r\n                                    </td>\r\n                                </tr>\r\n                                <tr>\r\n                                    <td style=\"text-align: center;\">\r\n\r\n                                        <span style=\"font-size: 18px;\">صديقنا المستكشف نقدم لك المادة المصوّرة للفصل الثاني عشر من المنهج التأسيسي1، يشرحه لك د. صلاح الراشد بعنوان</span></td>\r\n                                </tr>\r\n                                <tr>\r\n                                    <td style=\"text-align: center; height: 70px; font-size: x-large; font-weight: bold;\"><span style=\"color: #ff0000;\">\"منعطفات الوعي\"</span></td>\r\n                                </tr>\r\n                                <tr>\r\n                                    <td style=\"text-align: center; padding-top: 20px;\"><span style=\"font-size: 18px;\">لتحقيق الاستفادة والمتعة القصوى في التعلّم، نقترح عليك أن تتكرّم بالضغط على صورة الكراسة أدناه وطباعة محتواها، ثم استخدامها أثناء الاستماع إلى هذه المادة في مكان هادئ بعيداً عن المقاطعات</span></td>\r\n                                </tr>\r\n                                <tr>\r\n                                    <td>\r\n                                        <p style=\"text-align: center;\">\r\n                                            <a href=\"http://iacademypd.com/AttachFiles/korrassah-12.pdf\">\r\n                                                <img alt=\"\" width=\"171\" height=\"136\" style=\"border-color: black;\" src=\"images/notebook.jpg\" /></a>\r\n                                        </p>\r\n                                    </td>\r\n                                </tr>\r\n                                <tr>\r\n                                    <td style=\"padding-top: 20px;\" align=\"center\">\r\n\r\n                                        <table style=\"text-align: center;\" dir=\"rtl\">\r\n                                            <tbody>\r\n                                                <tr>\r\n                                                    <td>\r\n                                                        <div class=\"easyhtml5video\" style=\"position: relative; max-width: 592px;\">\r\n                                                            <video controls=\"controls\" poster=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/Part1.jpg\" style=\"width: 100%\" title=\"Part12-1\">\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/Part1.m4v\" type=\"video/mp4\" />\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/Part1.webm\" type=\"video/webm\" />\r\n                                                                <object type=\"application/x-shockwave-flash\" data=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/flashfox.swf\" width=\"500\" height=\"480\" style=\"position: relative;\">\r\n                                                                    <param name=\"movie\" value=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/flashfox.swf\" />\r\n                                                                    <param name=\"allowFullScreen\" value=\"true\" />\r\n                                                                    <param name=\"flashVars\" value=\"autoplay=False&amp;controls=true&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/Part1.jpg&amp;src=Part1.m4v\" />\r\n                                                                    <embed src=\"http://iacademypd.com/AttachFiles/Year1/Part12/Part12-1/eh5v.files/html5video/flashfox.swf\" width=\"592\" height=\"480\" style=\"position: relative;\" flashvars=\"autoplay=False&amp;controls=true&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/Part1.jpg&amp;src=Part1.m4v\" allowfullscreen=\"true\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer_en\" />\r\n                                                                    <img alt=\"Part12-1\" src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-1/eh5v.files/html5video/Part1.jpg\" style=\"position: absolute; left: 0;\" width=\"100%\" title=\"Video playback is not supported by your browser\" />\r\n                                                                </object>\r\n                                                            </video>\r\n                                                        </div>\r\n                                                        <strong><span style=\"font-size: large; color: #ff0000;\">الجزء الأول</span></strong>\r\n\r\n                                                    </td>\r\n                                                    <td>\r\n                                                        <div class=\"easyhtml5video\" style=\"position: relative; max-width: 592px;\">\r\n                                                            <video controls=\"controls\" poster=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/Part2.jpg\" style=\"width: 100%\" title=\"Part12-2\">\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/Part2.m4v\" type=\"video/mp4\" />\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/Part2.webm\" type=\"video/webm\" />\r\n                                                                <object type=\"application/x-shockwave-flash\" data=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/flashfox.swf\" width=\"500\" height=\"480\" style=\"position: relative;\">\r\n                                                                    <param name=\"movie\" value=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/flashfox.swf\" />\r\n                                                                    <param name=\"allowFullScreen\" value=\"true\" />\r\n                                                                    <param name=\"flashVars\" value=\"autoplay=False&amp;controls=true&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/Part2.jpg&amp;src=Part2.m4v\" />\r\n                                                                    <embed src=\"http://iacademypd.com/AttachFiles/Year1/Part12/Part12-2/eh5v.files/html5video/flashfox.swf\" width=\"592\" height=\"480\" style=\"position: relative;\" flashvars=\"autoplay=False&amp;controls=true&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/Part2.jpg&amp;src=Part2.m4v\" allowfullscreen=\"true\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer_en\" />\r\n                                                                    <img alt=\"Part12-2\" src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-2/eh5v.files/html5video/Part2.jpg\" style=\"position: absolute; left: 0;\" width=\"100%\" title=\"Video playback is not supported by your browser\" />\r\n                                                                </object>\r\n                                                            </video>\r\n                                                        </div>\r\n\r\n\r\n                                                        <strong><span style=\"font-size: large; color: #ff0000;\">الجزء الثاني</span></strong></td>\r\n                                                    <td>\r\n                                                        <div class=\"easyhtml5video\" style=\"position: relative; max-width: 592px;\">\r\n                                                            <video controls=\"controls\" poster=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/Part3.jpg\" style=\"width: 100%\" title=\"Part12-3\">\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/Part3.m4v\" type=\"video/mp4\" />\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/Part3.webm\" type=\"video/webm\" />\r\n                                                                <object type=\"application/x-shockwave-flash\" data=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/flashfox.swf\" width=\"500\" height=\"480\" style=\"position: relative;\">\r\n                                                                    <param name=\"movie\" value=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/flashfox.swf\" />\r\n                                                                    <param name=\"allowFullScreen\" value=\"true\" />\r\n                                                                    <param name=\"flashVars\" value=\"autoplay=False&amp;controls=true&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/Part3.jpg&amp;src=Part3.m4v\" />\r\n                                                                    <embed src=\"http://iacademypd.com/AttachFiles/Year1/Part12/Part12-3/eh5v.files/html5video/flashfox.swf\" width=\"592\" height=\"480\" style=\"position: relative;\" flashvars=\"autoplay=False&amp;controls=False&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/Part3.jpg&amp;src=Part3.m4v\" allowfullscreen=\"true\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer_en\" />\r\n                                                                    <img alt=\"Part12-3\" src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-3/eh5v.files/html5video/Part3.jpg\" style=\"position: absolute; left: 0;\" width=\"100%\" title=\"Video playback is not supported by your browser\" />\r\n                                                                </object>\r\n                                                            </video>\r\n                                                        </div>\r\n                                                        <strong><span style=\"font-size: large; color: #ff0000;\">الجزء الثالث</span></strong></td>\r\n                                                    <td>\r\n                                                        <div class=\"easyhtml5video\" style=\"position: relative; max-width: 592px;\">\r\n                                                            <video controls=\"controls\" poster=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/Part4.jpg\" style=\"width: 100%\" title=\"Part12-4\">\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/Part4.m4v\" type=\"video/mp4\" />\r\n                                                                <source src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/Part4.webm\" type=\"video/webm\" />\r\n                                                                <object type=\"application/x-shockwave-flash\" data=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/flashfox.swf\" width=\"500\" height=\"480\" style=\"position: relative;\">\r\n                                                                    <param name=\"movie\" value=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/flashfox.swf\" />\r\n                                                                    <param name=\"allowFullScreen\" value=\"true\" />\r\n                                                                    <param name=\"flashVars\" value=\"autoplay=False&amp;controls=true&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/Part4.jpg&amp;src=Part4.m4v\" />\r\n                                                                    <embed src=\"http://iacademypd.com/AttachFiles/Year1/Part12/Part12-4/eh5v.files/html5video/flashfox.swf\" width=\"592\" height=\"480\" style=\"position: relative;\" flashvars=\"autoplay=False&amp;controls=False&amp;fullScreenEnabled=true&amp;posterOnEnd=true&amp;loop=false&amp;poster=http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/Part4.jpg&amp;src=Part4.m4v\" allowfullscreen=\"true\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer_en\" />\r\n                                                                    <img alt=\"Part12-4\" src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part12/Part12-4/eh5v.files/html5video/Part4.jpg\" style=\"position: absolute; left: 0;\" width=\"100%\" title=\"Video playback is not supported by your browser\" />\r\n                                                                </object>\r\n                                                            </video>\r\n                                                        </div>\r\n                                                        <strong><span style=\"font-size: large; color: #ff0000;\">الجزء الرابع</span></strong></td>\r\n                                                    \r\n\r\n                                                </tr>\r\n                                            </tbody>\r\n                                        </table>\r\n\r\n                                    </td>\r\n                                </tr>\r\n                                <tr>\r\n                                    <td>\r\n                                        <p style=\"text-align: center; font-size: x-large; font-weight: bold\">\r\n                                            <a href=\"http://iacademypd.com/ViewVideos.aspx?id=vihVoSHf%2brFvvGg8GY25%2bQ%3d%3d\">إذا واجهتك مشكلة في فتح المواد ... الرجاء الضغط هنا \r\n                                            </a>\r\n\r\n                                        </p>\r\n                                    </td>\r\n                                </tr>\r\n                            </tbody>\r\n                        </table>\r\n                    </td>\r\n                </tr>\r\n\r\n            </tbody>\r\n        </table>\r\n        <div class=\"eh5v_script\"></div>\r\n        <script src=\"http://iacademypd.com/AttachFiles/Year1/Videos/Part1/Part1-3/eh5v.files/html5video/html5ext.js\" type=\"text/javascript\"></script>\r\n    </div>",

我已经将 url 存储在一个字符串中,但是我如何在 android 的 webview 中打开,注意这个 html 可能包含视频或音频甚至 pdf

提前致谢

【问题讨论】:

标签: android html url


【解决方案1】:

使用webView.loadData()

使用“数据”方案 URL 将给定数据加载到此 WebView。

webView.loadData(htmlStringData, "text/html", "UTF-8");

编辑

加载简单的 URL 使用

webView.loadUrl(url);

代码

if(isURL) // check here that `URL` or `HTML` 
{
   webView.loadUrl(url);
}else{
   webView.loadData(htmlStringData, "text/html", "UTF-8");
}

要加载两者,您需要检查您的 URL 是否包含 html 标记

【讨论】:

  • stackoverflow.com/users/7666442/nilu 如果我想要包含 html 和 http 链接的列表,并且我希望 webview 打开任何选定的链接,该怎么办http://iacademypd.com/AttachFiles/card-364aaa.jpg
  • @ahmedjallad 没找到你我的朋友
  • 我有一个列表,其中包含指向不同 url 的链接,有些是 html 格式,有些是媒体 (http:/myfile/images/hi.png),我怎样才能让同一个 webview 打开任何人如果他们点击了这些
  • 如果你想打开url而不是使用这个webView.loadUrl(url);
  • 我知道,但我的 url 来自服务器,所以如果 url 是 html 那么 webView.loadUrl(url) 不会工作,如果 url 是 .png 那么 webView.loadData(StringData, " text/html", "UTF-8") 不起作用
猜你喜欢
  • 2013-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-04
  • 1970-01-01
  • 2013-05-16
相关资源
最近更新 更多