[PHP]
package com.YOURCOMPANY.wms.previews;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
import com.wowza.util.FLVUtils;
import com.wowza.wms.amf.AMFPacket;
import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.application.WMSProperties;
import com.wowza.wms.http.IHTTPProvider;
import com.wowza.wms.http.IHTTPRequest;
import com.wowza.wms.http.IHTTPResponse;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.MediaStreamMap;
import com.wowza.wms.vhost.HostPort;
import com.wowza.wms.vhost.IVHost;
public class StreamsPreview implements IHTTPProvider {
IApplicationInstance appInstance;
public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
if(appInstance == null)
appInstance = vhost.getApplication(“YOURAPP”).getAppInstance(“definst”);
resp.setHeader(“Content-Type”, “video/x-flv”);
OutputStream out = resp.getOutputStream();
Map<String, List> params = req.getParameterMap();
if (params.containsKey(“preview”))
{
String action = params.get(“preview”).get(0);
MediaStreamMap streams = appInstance.getStreams();
IMediaStream stream = streams.getStream(action);
if (stream != null)
{
AMFPacket packet = stream.getLastKeyFrame();
if (packet != null)
{
FLVUtils.writeHeader(out, 0, null);
AMFPacket codecConfig = stream.getVideoCodecConfigPacket(packet.getAbsTimecode());
if (codecConfig != null)
FLVUtils.writeChunk(out, codecConfig.getDataBuffer(), codecConfig.getSize(), 0, (byte)codecConfig.getType());
FLVUtils.writeChunk(out, packet.getDataBuffer(), packet.getSize(), 0, (byte)packet.getType());
}
}
}
}
public void onBind(IVHost vhost, HostPort hostPort) {
}
public void onUnbind(IVHost vhost, HostPort hostPort) {
}
public void setProperties(WMSProperties properties) {
}
}
[/PHP]
have fun