如果您的视频聊天时间在聊天开始后没有改变,而不是单例,您可以实现一个模块并附加一个TimerTask
onplay
或publish
事件。下面是一个帮助您入门的示例。
import java.util.Timer;
import java.util.TimerTask;
import com.wowza.wms.amf.AMFDataList;
import com.wowza.wms.client.IClient;
import com.wowza.wms.logging.WMSLogger;
import com.wowza.wms.module.*;
import com.wowza.wms.request.RequestFunction;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.IMediaStreamActionNotify;
public class KillAfterNSeconds extends ModuleBase implements IMediaStreamActionNotify {
private class StreamKiller extends TimerTask{
private IMediaStream stream;
public StreamKiller(IMediaStream s){
this.stream = s;
}
@Override
public void run() {
try{
// Complete all your clean up, such as :
if(stream != null){
WMSLogger.getLogger("").info("Killing stream: " + stream.getName());
stream.getClient().shutdownClient();
stream.shutdown();
stream.close();
}
}catch(Exception e){}
}
}
public void publish(IClient paramIClient,
RequestFunction paramRequestFunction, AMFDataList paramAMFDataList) {
WMSLogger.getLogger("").info("Start running publish..");
IMediaStream stream = getStream(paramIClient, paramRequestFunction);
stream.addClientListener(this);
Timer timer = new Timer();
TimerTask task = new StreamKiller(stream);
// replace here with the actual time to kill stream
timer.schedule(task, 10000);
invokePrevious(paramIClient, paramRequestFunction, paramAMFDataList);
WMSLogger.getLogger("").info("Finish running publish..");
return;
}
@Override
public void onUnPublish(IMediaStream stream, String streamName,
boolean isRecord, boolean isAppend) {
WMSLogger.getLogger("").info("Start onUnPublish..");
double elapSeconds = stream.getElapsedTime().getTimeSeconds();
WMSLogger.getLogger("").info("Elapsed time " + elapSeconds);
WMSLogger.getLogger("").info("Finish running onUnPublish..");
}
@Override
public void onPause(IMediaStream arg0, boolean arg1, double arg2) {
}
@Override
public void onPlay(IMediaStream arg0, String arg1, double arg2,
double arg3, int arg4) {
}
@Override
public void onPublish(IMediaStream arg0, String arg1, boolean arg2,
boolean arg3) {
}
@Override
public void onSeek(IMediaStream arg0, double arg1) {
}
@Override
public void onStop(IMediaStream arg0) {
}
}