现在的位置: 首页 > 综合 > 正文

RED5的API介绍-2

2018年03月30日 ⁄ 综合 ⁄ 共 945字 ⁄ 字号 评论关闭
org.red5.server.api.scheduling
这是一个需要被实作的介面,我们可以实作此一介面,
并在此撰写每隔一段时间要自动执行的程式码。
在此package下有两个class,
IScheduledJob与ISchedulingService
以下是的一个实作IScheduledJob的范例程式
import org.red5.server.api.scheduling.IScheduledJob;
import org.red5.server.api.scheduling.ISchedulingService;
class MyJob implements IScheduledJob {
private Application app;
public MyJob(Application app) {
   this.app = app;
}
public void execute(ISchedulingService service)
   throws CloneNotSupportedException {
   // 在此写入要做的事
}
}
execute是IScheduledJob内要被我们实作的method
每隔一段时间,Server会自动执行execute这个函数
其传入的参数為一ISchedulingService型态的值
另外我们需要在此app被啟始时,新增这个排程
在实作ApplicationAdapter的appStart method裡新增下面两行
IScheduledJob job = new MyJob(this);
jobId = this.addScheduledJob(5000, job);
在appStop裡新增
this.removeScheduledJob(jobId);
IScheduledJob的相关说明请见
http://dl.fancycode.com/red5/api/org/red5/server/api/scheduling/IScheduledJob.html
ISchedulingService的相关说明请见
http://dl.fancycode.com/red5/api/org/red5/server/api/scheduling/ISchedulingService.html

(责任编辑:温莎)

【上篇】
【下篇】

抱歉!评论已关闭.