【问题标题】:Interfacing with Html And Android与 Html 和 Android 交互
【发布时间】:2012-09-14 08:36:14
【问题描述】:

我在Html 中开发了一个媒体播放器。现在我的工作是在Html 中播放streaming Url 来自Android 活动的编码媒体播放器。所以我需要将url 从android activity 传递给@ 987654326@ 将播放的媒体播放器文件。我搜索了很多,但没有找到任何好的解决方案。请建议我。谢谢

Java 代码

setContentView(R.layout.main);
//      String LocalFile = "file:///android_asset/android.html";

        WebView webView = (WebView) findViewById(R.id.webView1);
        String html = "<embed src=\"file:///android_asset/"
                + "android.html"
                + " \"play=\"true\" loop=\"true\" width=\"100%\" height=\"100%\"> <embed>";
        webView.getSettings().setPluginState(WebSettings.PluginState.OFF);
        webView.getSettings().setPluginsEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadDataWithBaseURL("file:///android_asset/", html,
                "text/html", "utf-8", null);
        String str = "rtmp://23.21.155.146:554/9016012507701502509011502505116016019xm150.sdp";
        webView.loadUrl("javascript:passWebUrl('" + str + "')");

我的媒体播放器代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>

    <style type="text/css" media="screen">
        html, body{
            margin:0;
            padding:0;
            height:100%;
        }
        #altContent{
            width:100%;
            height:100%;
        }
    </style>
    <title>YOUR TITLE HERE!</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

    <script type="text/javascript">
        var flashvars = {};
    function passWebUrl(url)
 {
        alert(url);
 }
        flashvars.HaloColor = "0x0086db";
        flashvars.ToolTips = "true";
        flashvars.AutoPlay = "true";
        flashvars.VolumeLevel = "50";
        flashvars.CaptionURL = "YOUR CAPTION HERE";
        flashvars.Title = "YOUR TITLE HERE";
        flashvars.Logo = "";
        flashvars.SRC = "Here is my url link should comes from Android Activity";
        flashvars.BufferTime = "5";
        flashvars.AutoHideControls = "false";
        flashvars.IsLive = "true";

        var params = {};
        params.wmode = "transparent";
        params.allowfullscreen = "true";

        var attributes = {};
        attributes.id = "L3MP";

        swfobject.embedSWF("http://media-player.cdn.level3.net/flash/v1_1_1/Level3MediaPlayer.swf", "altContent", "100%", "100%", "10.1.0","http://media-player.cdn.level3.net/flash/v1_1_1/expressInstall.swf", flashvars, params, attributes);
    </script>

    </head>
    <body>
     <div id="altContent">
       <center> <BR><BR><span style="color:red"><b>Please Install Adobe Flash Player</b>  
            </span><BR><BR>
      <a href="http://www.adobe.com/go/getflashplayer"><img     src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>
      </center>    
      </div>
     </body>
    </html>
    </script>
    </html>

【问题讨论】:

  • 拒绝投票的理由给出理由

标签: android html adobe media-player


【解决方案1】:

要将变量的值从您的 java 类传递到 html 页面中的 javascript 函数,您必须使用此代码。试试这个:

String str = "variable_value";
webView.loadUrl("javascript:functionName('"+ str +"')");

编辑:-

 function passWebUrl(url)
 {
        alert(url);
 }

【讨论】:

  • 谢谢@Chirag,但你告诉我如何在 Html 中获得这个值
  • @Dipu 你必须在 html 页面中使用字符串参数创建一个 javascript 函数。你在那个javascript函数中通过了str。
  • 我的 html 文件在 assets 文件夹中,那么我如何从 java 调用该 javascript 方法。请让我清楚
  • @Dipu 在您的 html 中创建上述函数并按照我的建议传递活动。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 2021-07-14
  • 1970-01-01
  • 2011-11-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多