写点什么

Red5 搭建直播平台,java 淘宝客教程

作者:Java高工P7
  • 2021 年 11 月 10 日
  • 本文字数:2370 字

    阅读完需:约 8 分钟

}


public boolean appConnect(IConnection conn, Object[] params)


{


log.info("oflaDemo appConnect");


measureBandwidth(conn);


if ((conn instanceof IStreamCapableConnection)) {


IStreamCapableConnection streamConn = (IStreamCapableConnection)conn;


/**


SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();


bwConfig.getChannelBandwidth()[3] = 1048576L;


bwConfig.getChannelInitialBurst()[3] = 131072L;


streamConn.setBandwidthConfigure(bwConfig);


*/


}


return super.appConnect(conn, params);


}


public void appDisconnect(IConnection conn)


{


log.info("oflaDemo appDisconnect");


if ((this.appScope == conn.getScope()) && (this.serverStream != null)) {


this.serverStream.close();


}


super.appDisconnect(conn);


}


}


5.2,增加所需要的 jar 文件spring-aop-3.0.5.RELEASE.jaraopalliance-1.0.jar


6,重启 Red5,访问路径http://localhost:5080/demos/ofla_demo.html,点击 Connect,右侧变绿,出现播放列表。选择播放文件。


7,使用 jwplayer,进行测试,书写代码如下


<script type="text/javascript" src="${pageContext.request.contextPath}/player/jwplayer.js"></script>


<div id="myElement" >Loading the player...</div>


jwplayer("myElement").setup({


file: "rtmp://localhost/oflaDemo/9.flv",


height: 360,


image: "${pageContext.request.contextPath}/images/button.gif",


width: 640


});


正常播放则测试成功。


8,进行二次开发


8.1,先写 Java 类


package first;


import org.red5.server.adapter.ApplicationAdapter;


import org.red5.server.api.IConnection;


import org.red5.server.api.IScope;


import org.red5.server.api.


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


stream.IServerStream;


import org.red5.server.api.stream.IStreamCapableConnection;


public class Application extends ApplicationAdapter


{


private IScope appScope;


private IServerStream serverStream;


public Application()


{


}


public boolean appStart(IScope app)


{


this.appScope = app;


return true;


}


public boolean appConnect(IConnection conn, Object[] params)


{


measureBandwidth(conn);


if ((conn instanceof IStreamCapableConnection)) {


IStreamCapableConnection streamConn = (IStreamCapableConnection)conn;


}


return super.appConnect(conn, params);


}


public void appDisconnect(IConnection conn)


{


if ((this.appScope == conn.getScope()) && (this.serverStream != null)) {


this.serverStream.close();


}


super.appDisconnect(conn);


}


}


8.2 配置 red5-web.properties,内容如下


webapp.contextPath=/red58


webapp.virtualHosts=*


8.3 配置 red5-web.xml


<?xml version="1.0" encoding="UTF-8" ?>


<beans xmlns="http://www.springframework.org/schema/beans"


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


xmlns:lang="http://www.springframework.org/schema/lang"


xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd


http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">


<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">


<property name="location" value="/WEB-INF/red5-web.properties" />


</bean>


<bean id="web.context" class="org.red5.server.Context" autowire="byType" />


<bean id="web.scope" class="org.red5.server.WebScope" init-method="register">


<property name="server" ref="red5.server" />


<property name="parent" ref="global.scope" />


<property name="context" ref="web.context" />


<property name="handler" ref="web.handler" />


<property name="contextPath" value="${webapp.contextPath}" />


<property name="virtualHosts" value="${webapp.virtualHosts}" />


</bean>


<bean id="web.handler" class="first.Application" />


</beans>


8.4 配置 web.xml


<?xml version="1.0" encoding="ISO-8859-1"?>


<web-app


xmlns="http://java.sun.com/xml/ns/j2ee"


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"


version="2.4">


<display-name>red58</display-name>


<context-param>


<param-name>webAppRootKey</param-name>


<param-value>/red58</param-value>


</context-param>


<servlet>


<servlet-name>rtmpt</servlet-name> <servlet-class>org.red5.server.net.rtmpt.RTMPTServlet</servlet-class>


<load-on-startup>1</load-on-startup>


</servlet>


<servlet-mapping>


<servlet-name>rtmpt</servlet-name>


<url-pattern>/fcs/*</url-pattern>


</servlet-mapping>


<servlet-mapping>


<servlet-name>rtmpt</servlet-name>


<url-pattern>/open/*</url-pattern>


</servlet-mapping>


<servlet-mapping>


<servlet-name>rtmpt</servlet-name>


<url-pattern>/close/*</url-pattern>


</servlet-mapping>


<servlet-mapping>


<servlet-name>rtmpt</servlet-name>


<url-pattern>/send/*</url-pattern>


</servlet-mapping>


<servlet-mapping>


<servlet-name>rtmpt</servlet-name>


<url-pattern>/idle/*</url-pattern>


</servlet-mapping>


<security-constraint>


<web-resource-collection>


<web-resource-name>Forbidden</web-resource-name>


<url-pattern>/streams/*</url-pattern>


</web-resource-collection>


<auth-constraint/>

用户头像

Java高工P7

关注

还未添加个人签名 2021.11.08 加入

还未添加个人简介

评论

发布
暂无评论
Red5搭建直播平台,java淘宝客教程