问题
I am trying to publish dynamic RTMP stream with javascript and php.
I want to get stream name from url and publish the stream on my web player (jwplayer)
like xxx.com/watch.php?chanel=music
I want to use the music as my stream name and want to show the stream with my jwplayer. Suppose my rtmp hosting is rtmp://xx.yy.zz.yy:1987/live
Now I want to get the stream name music from the url and publish the full stream rtmp://xx.yy.zz.yy:1987/live/music
through jwplayer dynamically.
if someone hit xxx.com/watch.php?chanel=sports he will able to see rtmp://xx.yy.zz.yy:1987/live/sports
stream.
I wrote the following script but its not working
<?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");
?>
Now when I am hitting the http://www.justlive24.com/watch.php?chanel=shomoy its not loading the player. I am newbie and trying to find out the solution. Your brief explanation will help me to understand this.
回答1:
you've syntax error:
1. http://joxi.ru/nvGdUxjKTJBNH3ESafE
2. http://joxi.ru/yPGdU_3JTJA7Y4XfP7M
also some fixes todo...
try this code: http://pastebin.com/UzhuVpXm
don't forget to attach jquery between head tags
回答2:
try this:
<?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");
?>
来源:https://stackoverflow.com/questions/24233131/dynamic-rtmp-streaming-with-jwplayer