4.11 RTMP直播

 

 

RTMP(Real Time Messaging Protocol)实时消息传送协议是Adobe Systems公司为Flash播放器和服务器之间音频、视频和数据传输开发的私有协议。

本播放器,既支持http协议,也rtmp协议。并且只须设置rtmp服务器JcScpServer参数,即可,很方便,其它代码不变。

 

常见问题:对于很多用户对于直播流rtmp地址的写法有疑问,在这特别说明一下:

1. 用户通过自建流媒体服务器或通过云服务器,得到的直播流地址,通常有两部分组成,即:【流媒体服务器地址】 和 【流名称(也叫节点名)】,举例,假设你从云服务商处,得到的完整直播地址是:
rtmp://www.abc.com/live/livestream (注意折成两部门,前部分为流媒体服务器地址,后者为流名称)
2. 那么,如上,它的【流媒体服务器地址】JcScpServer 参数 对应的是:rtmp://www.abc.com/live
【流名称(也叫节点名)】JcScpVideoPath 参数 对应的是:livestream
即:

//假设完整直播流地址为 rtmp://www.abc.com/live/livestream
//折开成【流媒体服务器】和【流名称】两部分后,参考如下
......
so.addVariable("JcScpServer","rtmp://www.abc.com/live"); //您的rtmp流媒体服务器地址
so.addVariable("JcScpVideoPath","livestream"); //流名称
......

 

RTMP直播范例:

网页视频播放器加载中,请稍后...

 

例(4.12)-1:rtmp协议下的播放器调用代码示例

<script type="text/javascript" src="/player/js/swfobject.js"></script>
<div class="video" id="CuPlayer"> <b> <img src="/player/images/loading.gif" /> 网页视频播放器加载中,请稍后...</b> </div>
<script type="text/javascript">
var so = new SWFObject("/player/player.swf","ply","980","460","9","#000000");
so.addParam("allowfullscreen","true");
so.addParam("allowscriptaccess","always");
so.addParam("wmode","opaque");
so.addParam("quality","high");
so.addParam("salign","lt");
<!-- HTML代码参数/Begin -->
so.addVariable("JcScpServer","rtmp://www.yourServer.com/live"); //您的rtmp流媒体服务器地址
so.addVariable("JcScpVideoPath","livestream"); //流名称
so.addVariable("JcScpImg","/player/images/startpic.jpg"); //视频缩略图
so.addVariable("JcScpFile","/player/CuSunV4set.xml"); //配置文件
<!-- HTML代码参数/End -->
so.write("CuPlayer");
</script>

 

例(4.12)-2:rtmp协议下的播放器调用代码示例

第1部分:

<script type="text/javascript" src="/player/js/swfobject.js"></script>
<div class="video" id="CuPlayer"> <b> <img src="/player/images/loading.gif" /> 网页视频播放器加载中,请稍后...</b> </div>
<script type="text/javascript">
var so = new SWFObject("/player/player.swf","ply","980","460","9","#000000");
so.addParam("allowfullscreen","true");
so.addParam("allowscriptaccess","always");
so.addParam("wmode","opaque");
so.addParam("quality","high");
so.addParam("salign","lt");
<!-- HTML代码参数/Begin -->
so.addVariable("JcScpFile","/player/CuSunV4set.xml"); //配置文件
<!-- HTML代码参数/End -->
so.write("CuPlayer");
</script>

 

第2部分,以下是配置文件CuSunV4set.xml代码如下(直播时,把JcScpLiveMode直播模式值设为 1,隐藏进度条):

<CuPlayer>
<Player_Set
JcScpBufferTime = "5"
JcScpVolume = "75"
JcScpCode = "utf8"
JcScpImgDisplay = "no"
JcScpAutoHideControl ="yes"
JcScpControlHideTime="0.5"
JcScpControlHeight="40"
JcScpShowList= "yes"
JcScpAutoRepeat = "no"
JcScpsetMode = "1"
JcScpAFrontCanClose = "no"
JcScpShowRightmenu = "yes"
JcScpShareMode = "JcScpVideoPath"
JcScpLoadbarMode = "0"
JcScpLiveMode = "1"
/>
<Logo_Set
JcScpLogoDisplay = "yes"
JcScpLogoPath = "images/logo.png"
JcScpLogoPosition = "top-left"
JcScpLogoWidth = "165"
JcScpLogoHeight = "75"
JcScpLogoAlpha = "1"
/>
<Flashvars_Set
JcScpServer ="rtmp://www.yourServer.com/live"
JcScpVideoPath = "livestream"
JcScpVideoPathHD = ""
JcScpImg ="images/startpic.jpg"
JcScpAutoPlay = "yes"
JcScpStarTime = "0"
JcScpEndTime = "0"
JcScpCuePointInfo = ""
JcScpCuePointTime = ""
......
......