制作视频会议应用时,经常有客户要求能够同时将会议储存下来。平时,我们会利用Netstream Object,其中一方发出一个Live Stream:
ns.publish("testStream", "live");
观看一方则用:
ns.play("testStream", -1);
如果将Live改为Record或者Append,这个Live Stream就会同时储存在FlashCom Application下的streams的Instance Folder里,名称为testStream.flv,而观看一方继续可以收到。虽然这个方法很简单,但却应付不到现实世界的要求,因为客户希望要一个Button,控制会议有时会储存,有时不会储存。
很自然地,可以编写一个Function,切换ns.publish的参数,一时用Live,一时用Append。 可是,当Stream由Append(储存)变成Live(不储存)时,Flashcom会自动将之前储存的FLV删除!
解决方法一(不建议使用)
那么用两个NetStream Objects,ns1:负责Live Stream,发放给观看一方;ns2:负责Append,发放给FlashCom储存。 如果要暫停儲存,可以用:如果要暂停储存,可以用:
ns2.publish(false);
虽然这可以解决了参数Live会删除FLV的问题,却花了多一倍Bandwidth,不化算。
解决方法二
利用Server-side Stream Object,它就是FlashCom Server-side的NetStream Object,原来的作用是用来作视频分流,可以由一个FlashCom A要求视频流到FlashCom B,再由FlashCom B发放到Client的Flash Player里,借以解决FlashCom Server License上的Bandwidth限制。
这里利用Stream Object接收Client传来的Live Stream(testStream),然后将它另存为testRecord.flv。 Client-side ActionScript如常是:
ns.publish("testStream", "live");
erver-side的main.asc:
//储存的名称
this.s = Stream.get("testRecord");
// Client传来的Live Stream的名称
this.s.play("testStream", -1, -1);
//开始储存
this.s.record();
this.s.onStatus = function(info) { this.s.onStatus = function(info) {
{ if (info.description == "testStream is now unpublished.") {
//当Client停止传来时,就停止储存
this.play(false);
this.record(false);
} }
}
根据FlashCom Help > Server-Side Communication ActionScript Dictionary > Server-Side Communication ActionScript > Stream.record,里面指要停止储存,只需要用参数false,这是错误的。用Communication App Inspector监测,当应用结束,仍然有一个Stream Publishing继续执行着,因为Stream.play()没有被停止,所以真正要停止储存时,必须先用Stream.play(false);停止Stream Publishing,然后才用Stream.record (false);。