我有一个为我的Flash客户端提供Live Streaming的Java应用程序,现在流媒体的东西可以工作,但我如何在Red5服务器上存储流,我确定我上次听说你需要将流存储在你的webapps文件夹中但我不知道我是不对。
stream变量是否为空?
以下是目前的代码:
package com;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.scope.IScope;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.stream.ClientBroadcastStream;
import static java.lang.System.*;
public class Application extends ApplicationAdapter{
//private static final Log log = LogFactory.getLog( Application.class );
public boolean appStart(IScope scope){
//IConnection current = Red5.getConnectionLocal();
return true;
}
public void appStop(){
// This function fires when the app is closing
}
public boolean connect(IConnection conn, IScope scope, Object[] params) {
// This is the master connection method called every time someone connects
// to the serv
IConnection clientConnection = Red5.getConnectionLocal(); // Get the connection
String clientIP = clientConnection.getRemoteAddress(); // Get the user's IP // // Format the current date
//IBroadcastStream currentStream = app.getBroadcastStream(clientConnection.getScope(), "hostStream"); // Get the current stream
ClientBroadcastStream stream = (ClientBroadcastStream) getBroadcastStream(conn.getScope(), "tester");
try {
// Save the stream to disk.
stream.saveAs("streamName", false);
} catch (Exception e) {
System.out.println(e.toString());
}
return true;
}
/*
* (non-Javadoc)
* @see org.red5.server.adapter.ApplicationAdapter#disconnect(org.red5.server.api.IConnection, org.red5.server.api.IScope)
* disconnect an user form the chat and notify all others users
*/
public void disconnect(IConnection conn, IScope scope) {
// Function called every time someone disconnects from the server.
super.disconnect(conn, scope);
}
public boolean joinuser(String username, String uid) {
out.println("join invoked: "+username+" "+uid);
return true;
}
public boolean removeuser(String username, String uid) {
out.println("remove invoked: "+username+" "+uid);
return true;
}
}
我收到一条错误消息,说该文件无法保存在“streams / aaa.flv”中,错误显示文件路径无法解析,因为connect方法中不存在该URL。
package com;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.scope.IScope;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IServerStream;
import org.red5.server.api.stream.support.SimplePlayItem;
import org.red5.server.api.stream.support.StreamUtils;
import org.red5.server.stream.ClientBroadcastStream;
import org.red5.server.stream.RecordingListener;
import static java.lang.System.*;
public class Application extends ApplicationAdapter{
//private static final Log log = LogFactory.getLog( Application.class );
private IServerStream serverStream;
public boolean appStart(IScope scope){
//IConnection current = Red5.getConnectionLocal();
return true;
}
public void appStop(){
// This function fires when the app is closing
}
@Override
public void streamPublishStart(IBroadcastStream stream)
{
stream.addStreamListener(new MyStreamListener());
}
@Override
public void streamBroadcastStart(IBroadcastStream stream) {
IConnection conn = Red5.getConnectionLocal();
super.streamBroadcastStart(stream);
//log.info("streamBroadcastStart " + stream.getPublishedName() + " " + System.currentTimeMillis() + " " + conn.getScope().getName());
//recordStream(stream);
//MyStreamListener listener = new MyStreamListener();
//listener.setEventRecordingService(recordingService);
//stream.addStreamListener(listener);
//streamListeners.put(conn.getScope().getName() + "-" + stream.getPublishedName(), listener);
}
private void recordStream(IBroadcastStream stream) {
IConnection conn = Red5.getConnectionLocal();
long now = System.currentTimeMillis();
String recordingStreamName = stream.getPublishedName(); // + "-" + now; /** Comment out for now...forgot why I added this - ralam */
try {
System.out.println("Recording stream " + recordingStreamName );
ClientBroadcastStream cstream = (ClientBroadcastStream) this.getBroadcastStream(conn.getScope(), stream.getPublishedName());
cstream.saveAs(recordingStreamName, false);
} catch(Exception e) {
System.out.println("ERROR while recording stream " + e.getMessage());
e.printStackTrace();
}
}
public boolean connect(IConnection conn, IScope scope, Object[] params) {
// This is the master connection method called every time someone connects
// to the serv
IConnection clientConnection = Red5.getConnectionLocal(); // Get the connection
String clientIP = clientConnection.getRemoteAddress(); // Get the user's IP // // Format the current date
//IBroadcastStream currentStream = app.getBroadcastStream(clientConnection.getScope(), "hostStream"); // Get the current stream
ClientBroadcastStream stream = (ClientBroadcastStream) getBroadcastStream(conn.getScope(), "tester");
//stream.addStreamListener(new MyStreamListener());
serverStream = StreamUtils.createServerStream(clientConnection.getScope(), "live0");
SimplePlayItem item = SimplePlayItem.build(clientIP);
//item.setStart(0);
//item.setLength(10000);
//item.setName("avatar");
serverStream.addItem(item);
serverStream.start();
try {
serverStream.saveAs("aaa", false);
} catch (Exception e) {}
try {
// Save the stream to disk.
// System.out.println("hello");
//stream.saveAs("/stream1", false);
// System.out.println("hello2");
} catch (Exception e) {
System.out.println("sdfsdfsdf" + e.toString());
}
return true;
}
/*
* (non-Javadoc)
* @see org.red5.server.adapter.ApplicationAdapter#disconnect(org.red5.server.api.IConnection, org.red5.server.api.IScope)
* disconnect an user form the chat and notify all others users
*/
public void disconnect(IConnection conn, IScope scope) {
// Function called every time someone disconnects from the server.
super.disconnect(conn, scope);
}
public boolean joinuser(String username, String uid) {
out.println("join invoked: "+username+" "+uid);
return true;
}
public boolean removeuser(String username, String uid) {
out.println("remove invoked: "+username+" "+uid);
return true;
}
}