当前位置:网站首页>Red5搭建直播平台
Red5搭建直播平台
2022-08-04 19:56:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
下载地址 http://www.red5.org/
1, 首先启动red5
3,在该页面点击installer,进入安装页面。或输入http://localhost:5080/installer/
4,安装oflaDemo
5,可能会报错,下面来解决这些基本问题。
5.1,重新编译Application.java
package org.red5.demos.oflaDemo;
import org.red5.logging.Red5LoggerFactory;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.stream.IServerStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.slf4j.Logger;
public class Application extends ApplicationAdapter
{
private static Logger log = Red5LoggerFactory.getLogger(Application.class, "oflaDemo");
private IScope appScope;
private IServerStream serverStream;
public Application()
{
log.info("oflaDemo created");
System.out.println("oflaDemo created");
}
public boolean appStart(IScope app)
{
log.info("oflaDemo appStart");
System.out.println("oflaDemo appStart");
this.appScope = app;
return true;
}
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.jar
和aopalliance-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.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/>
</security-constraint>
</web-app>
8.5 在WebContent\streams里放置flv等类型文件
8.6 发布文件,名称为red58
8.7,发布时,删除lib文件夹中的文件
8.8 进行测试。
<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/red58/9.flv",
height: 360,
image: "${pageContext.request.contextPath}/images/button.gif",
width: 640
});
Js代码 收藏代码
jwplayer().onBeforePlay( function(event){
//alert("before Play");
});
jwplayer().onPlay( function(event){
//alert(" Play");
});
jwplayer().onSeek( function(event){
//alert("before Play");
alert("seek--position:"+event.position +"---offset :"+event.offset );
});
jwplayer().onTime( function(event){
//this event is fired as the playback position gets updated
//alert("onTime--position:"+event.position +"---duration :"+event.duration );
});
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106432.html原文链接:https://javaforall.cn
边栏推荐
- Initialization process of SAP UI5
- 《支付宝体验设计精髓》一书,跟测试相关性知识记录
- How to promote the implementation of rural revitalization
- 如何手动下载并安装 Visual Studio Code 的 SAP Fiori tools - Extension Pack
- 性能测试流程
- 完善的交叉编译环境记录 peta 生成的shell 脚本
- 二叉树是否对称
- really time ntp service start command
- 【Attention 演变史】RNN的产生、架构、推广、问题(第一弹)
- SQL Server 遇到报错解决办法--更新中
猜你喜欢
C语言——青蛙跳台阶(递归)
Notepad++更改显示背景
The book "The Essence of Alipay Experience Design", a record of knowledge related to testing
Go study notes (Part 1) Configuring the Go development environment
PG网络传输安全SSL介绍及使用示例
图片延迟加载、预加载
In July 2022, domestic database memorabilia
面试官:JVM运行时数据区包含哪几部分?作用是啥?
Seata source code analysis: various message processing processes of seata server
实现菜单拖拽排序
随机推荐
C#弹出询问对话框
前3名突然变了,揭秘 7 月编程语言最新排行榜
5 g NR notes
取证程序分类
SQL Server 遇到报错解决办法--更新中
按需视觉识别:愿景和初步方案
c sqlite...
高效目标检测:动态候选较大程度提升检测精度(附论文下载)
「 WAIC 2022 · 黑客马拉松」蚂蚁财富两大赛题邀你来战!
MYSQL获取数据库的表名和表注释
【Web漏洞探索】跨站脚本漏洞
二叉树的遍历
SAP UI5 的初始化过程
Initialization process of SAP UI5
ASP.NET商贸进销存管理系统源码(带数据库文档)源码免费分享
Go study notes (Part 1) Configuring the Go development environment
正畸MIA微种植体支抗技术中国10周年交流会在沈举办
Regular expression is incomplete
seata源码解析:seata server各种消息处理流程
成品升级程序