【问题标题】:Dynamic rtmp streaming with jwplayer使用 jwplayer 进行动态 rtmp 流式传输
【发布时间】:2014-08-05 15:42:56
【问题描述】:

我正在尝试使用 javascript 和 php 发布动态 RTMP 流。

我想从 url 获取流名称并将流发布到我的网络播放器 (jwplayer) 喜欢xxx.com/watch.php?chanel=music

我想使用音乐作为我的流名称,并想用我的 jwplayer 显示流。假设我的 rtmp 主机是rtmp://xx.yy.zz.yy:1987/live

现在我想从 url 中获取流名称 music 并通过 jwplayer 动态发布完整流 rtmp://xx.yy.zz.yy:1987/live/music

如果有人点击 xxx.com/watch.php?chanel=sports,他将能够看到rtmp://xx.yy.zz.yy:1987/live/sports 流。

我写了以下脚本,但它不起作用

<?php
include ("template/header.html");
?>
<div class="container-fluid">
<script src="stream/jwplayer.js"></script>
<div id="mediaplayer">This div will be replaced by the JW Player</div>
<script>

<script>
var chanel = getQueryVariable("chanel");

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 

}
var host= ("rtmp://216.245.200.114/Live/");
var stream=host.concat(chanel);
jwplayer('mediaplayer').setup({
width: "600",
height: "500",
primary: "flash",
autostart: "true",
repeat: 'always',
sources:[
{   file: stream    }
]
});
</script>
</div>
<?php
include ("template/footer.html");
?>

现在当我点击http://www.justlive24.com/watch.php?chanel=shomoy 时,它不会加载播放器。我是新手并试图找出解决方案。您的简短解释将有助于我理解这一点。

【问题讨论】:

    标签: javascript php stream jwplayer wowza


    【解决方案1】:

    你有语法错误:
    1.http://joxi.ru/nvGdUxjKTJBNH3ESafE
    2.http://joxi.ru/yPGdU_3JTJA7Y4XfP7M
    还有一些修复待办事项...

    试试这个代码:http://pastebin.com/UzhuVpXm

    不要忘记在head标签之间附加jquery

    【讨论】:

    • 非常感谢您解决了我的问题。我绝对是新人,所以我犯了一些愚蠢的错误。感谢您修复它。它现在正在工作。
    • 不错。乐于助人(:
    【解决方案2】:

    试试这个:

    <?php
    include ("template/header.html");
    ?>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="stream/jwplayer.js"></script>
    
        <div class="container-fluid">
            <div id="mediaplayer">This div will be replaced by the JW Player</div>
            <script>
                function getQueryVariable(variable) {
                    var query = window.location.search.substring(1);
                    var vars = query.split("&");
                    for (var i=0;i<vars.length;i++) {
                        var pair = vars[i].split("=");
                        if (pair[0] == variable) {
                            return pair[1];
                        }
                    }
                    return '';
                }
                $(function(){
                    var chanel = getQueryVariable("chanel");
                    var host= "rtmp://216.245.200.114/Live/";
                    var stream=host+chanel;
                    jwplayer('mediaplayer').setup({
                        width: "600",
                        height: "500",
                        primary: "flash",
                        autostart: "true",
                        repeat: 'always',
                        sources:[
                            {   file: stream    }
                        ]
                    });
                });
            </script>
        </div>
    <?php
    include ("template/footer.html");
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-22
      • 2017-10-27
      • 2023-03-13
      • 2012-11-14
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多