Red5搭建直播平台

Red5搭建直播平台Red5搭建直播平台

大家好,又见面了,我是你们的朋友全栈君。

下载地址 http://www.red5.org/

1, 首先启动red5

2,访问http://localhost:5080/

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.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.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.net/106432.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 史上最简单的 MyBatis 教程(一)

    史上最简单的 MyBatis 教程(一)1简介MyBatis是支持普通SQL查询,存储过程和高级映射的优秀持久层框架,其几乎消除了所有的JDBC代码和参数的手工设置以及结果集的检索。MyBatis使用简单的XML或注解用于配置和原始映射,将接口和Java的POJOs(PlainOldJavaObjects,普通的Java对象)映射成数据库中的记录。MyBatis应用程序大都使用SqlSessionFac

    2025年7月22日
    1
  • ubuntu更新源报错_cydia更新软件源很慢

    ubuntu更新源报错_cydia更新软件源很慢错误我在Ubuntu上的/etc/apt/sources.list加入源后执行sudoapt-getupdate出现下图错误:原因在sources.list文件中加入了非ubuntu官方源,所以认为加入源是不可信任的。解决方法导入该源公钥。E084DAB9为上图中公钥后八位gpg–keyserverkeyserver.ubuntu.com-

    2022年10月13日
    3
  • radius认证服务器ip该怎么填_radius认证服务器拒绝原因

    radius认证服务器ip该怎么填_radius认证服务器拒绝原因1.AAA和Radius概述  AAA是验证授权和记账Authentication,Authorization,andAccounting的简称。它是运行于NAS上的客户端程序,它提供了一个用来对验证、授权和记账这三种安全功能进行配置的一致的框架。AAA的配置实际上是对网络安全的一种管理,这里的网络安全主要指访问控制,包括哪些用户可以访问网络服务器,具有访问权的用户可以得到哪些服务,如何

    2025年8月3日
    7
  • @scheduled注解 定时任务控制(Spring响应式编程)

    概念项目经常会用到定时任务,实现定时任务的方式有很多种,参考Spring定时任务的几种实现。在Spring框架中,实现定时任务很简单。常用的实现方式是使用注解@Schedule。@Schedule常用来实现简单的定时任务。例如凌晨1点跑批,每1小时更新订单状态等。非SpringBoot项目springmvc-servlet.xml中添加配置&amp;amp;amp;amp;lt;!–xmlns加入–&amp;amp;amp;amp;gt;…

    2022年4月16日
    162
  • 恐怖保姆下载安装汉化版_eclipse汉化不成功怎么办

    恐怖保姆下载安装汉化版_eclipse汉化不成功怎么办eclipse汉化官方汉化包首先,在eclipseIDE中找到’help’,打开’Installnewsoftware…’在点击弹出的新窗口中的Add按钮,Name项任意填Location项是在Eclipse官方的babel语言包project网页上找的,需要自行去查看最新的location查看最新Location方法:https://www.eclipse.org/babel/downloads.php、打开上面网站找到,红框框住的部分,复制地址后,填写到Lo

    2022年5月3日
    62
  • 像素和毫米的换算_1500像素等于多少毫米

    像素和毫米的换算_1500像素等于多少毫米屏幕PPI计算:(White^2+Height^2)^0.5/屏幕大小英寸数毫米和像素换算:mm=(px/dpi)*25.4px=(mm*dpi)/25.4英寸=px/dpi1英寸=25.4毫

    2022年8月2日
    21

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号