load html media like video, audio and pdf from url in android

时间:2017-12-18 06:04:59

标签: android html url

im developing android application the loads different media type from the server, the media comes in html format like this :

          {
    "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>",

i already stored the url in a string but how can i open in webview in android, notice that this html may contain video or audio or even pdf

thanks in advance

1 个答案:

答案 0 :(得分:1)

Use webView.loadData()

Loads the given data into this WebView using a 'data' scheme URL.

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

EDIT

to load simple URL use

webView.loadUrl(url);

CODE

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

to load both you need to check weather you URL contain html tag or not