[Red5] server side streams
Daniel Rossi
spam at electroteque.org
Thu Sep 27 20:46:29 PDT 2007
Here is my custom class, its working for one trailer. This particular
one the server does not like yet so it doesnt send complete status,
metadata problem in sorenson squeeze maybe ? Its cutting the clip 2
second too short now rather than 10 seconds too short maybe thats
because i have a buffer time set to 2 instead of 10 ? It will only
work for one file loaded but thats fine with me right now.
package playlists;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Iterator;
import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.springframework.core.io.Resource;
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.api.IConnection;
public class ServerPlaylist {
protected static Log log = LogFactory.getLog
(ServerPlaylist.class.getName());
private String path = "";
private String pattern = "";
private String name = "";
private Boolean repeat = true;
private IScope appScope;
private IServerStream serverStream;
private String formatDate(Date date) {
SimpleDateFormat formatter;
String pattern = "dd/MM/yy H:mm:ss";
Locale locale = new Locale("en", "US");
formatter = new SimpleDateFormat(pattern, locale);
return formatter.format(date);
}
public void setRepeat(Boolean repeat)
{
this.repeat = repeat;
}
public void setPath(String path)
{
this.path = path;
}
public void setPattern(String pattern)
{
this.pattern = pattern;
}
public void setStreamName(String name)
{
this.name = name;
}
public void start(IConnection conn)
{
//if (appScope == conn.getScope()) {
serverStream = StreamUtils.createServerStream(conn.getScope(),
this.name);
SimplePlayItem item = new SimplePlayItem();
Map map = getDirectoryFileList(this.path, this.pattern);
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
HashMap<String, Object> value = (HashMap<String, Object>)
map.get(key);
item.setName(key);
serverStream.addItem(item);
log.debug("Adding " + value.get("name") + " to server playlist
in order");
}
serverStream.start();
serverStream.setRepeat(this.repeat);
//}
}
public Map getDirectoryFileList(String path, String pattern) {
IScope scope = Red5.getConnectionLocal().getScope();
Map<String, Map> filesMap = new HashMap<String, Map>();
Map<String, Object> fileInfo;
try {
log.debug("getting the FLV files");
Resource[] flvs = scope.getResources(path + pattern);
if (flvs != null) {
for (Resource flv : flvs) {
File file = flv.getFile();
Date lastModifiedDate = new Date(file.lastModified());
String lastModified = formatDate(lastModifiedDate);
String flvName = flv.getFile().getName();
String flvBytes = Long.toString(file.length());
if (log.isDebugEnabled()) {
log.debug("flvName: " + flvName);
log.debug("lastModified date: " + lastModified);
log.debug("flvBytes: " + flvBytes);
log.debug("-------");
}
fileInfo = new HashMap<String, Object>();
fileInfo.put("name", flvName);
fileInfo.put("lastModified", lastModified);
fileInfo.put("size", flvBytes);
filesMap.put(flvName, fileInfo);
}
}
} catch (IOException e) {
log.error(e);
}
return filesMap;
}
}
On 28/09/2007, at 1:10 PM, Daniel Rossi wrote:
> woops hold off on that one, it doesnt goto the next in the list,
> and it will start playing from the last in the list not the first one
>
> if (appScope == conn.getScope()) {
>
> serverStream = StreamUtils.createServerStream(appScope, "live0");
> SimplePlayItem item = new SimplePlayItem();
>
> item.setName("IronMan");
>
> serverStream.addItem(item);
>
> item.setName("on2_flash8_w_audio");
>
> serverStream.addItem(item);
>
> serverStream.start();
> serverStream.setRepeat(true);
>
> }
>
> plays this first on2_flash8_w_audio and yes it seems to repeat on
> the last file.
>
> On 28/09/2007, at 12:05 PM, Daniel Rossi wrote:
>
>> Hi there steve and others i believe the problem with server side
>> streams was a badly encoded video thats why it was stopping early and
>> skipping. The star wars trailer works perfect in the latest svn. Ill
>> give it a try now switching to a live broadcaster inside the app.
>>
>> _______________________________________________
>> Red5 mailing list
>> Red5 at osflash.org
>> http://osflash.org/mailman/listinfo/red5_osflash.org
>
> _______________________________________________
> Red5 mailing list
> Red5 at osflash.org
> http://osflash.org/mailman/listinfo/red5_osflash.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5_osflash.org/attachments/20070928/212e7ed4/attachment-0001.html
More information about the Red5
mailing list