下载地址 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.jar
和aopalliance-1.0.jar
6,重启Red5,访问路径http://localhost:5080/demos/ofla_demo.html,点击Connect,右侧变绿,出现播放列表。选择播放文件。
7,使用jwplayer,进行测试,书写代码如下
Loading the player...
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
8.4 配置web.xml
red58
webAppRootKey
/red58
rtmpt org.red5.server.net.rtmpt.RTMPTServlet
1
rtmpt
/fcs/*
rtmpt
/open/*
rtmpt
/close/*
rtmpt
/send/*
rtmpt
/idle/*
Forbidden
/streams/*
8.5 在WebContent\streams里放置flv等类型文件
8.6 发布文件,名称为red58
8.7,发布时,删除lib文件夹中的文件
8.8 进行测试。
Loading the player...
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 );
});