
Running an application like the videoconference, the images will be losted. But we can have "persistence" of image, sound and text using FlashComm.
For text persistence, our recomendation is not use the FlashComm resources but a SQL database and ASP .NET code. We have, here in this site, a FREE course about this subject (the link).
When we record a video or sound, will be created, at the "application folder", 2 files for each stream, having the extentions: .FLD and .IDX.
To begin recording an stream, we use a line of code like:
out_ns.publish("name-for-the-stream", "record");
To finish recording:
out_ns.close();
To play, we need to create another stream and use:
in_ns.play("name-for-the-stream");
We can capture the end of playing using:
in_ns.onStatus = function(info){
if (info.code == "NetStream.Play.Stop"){
//some action
}
}
To erase an stream we need to create a main.asc program and start a method in the server from the client (we have learned how to do this in previous lesson, here).
At our exercice we will have 2 streams beeing recorded simultaneously: a video stream and a sound stream. The name of this streams will be created from an input of the user, adding the letters "v" and "s" for each stream. At the server, the program main.asc to erase this streams will be:
application.onConnect=function(client){
application.acceptConnection(client);
client.eraseSt=function(name){
vs = Stream.get("v"+name);
ss = Stream.get("s"+name);
if(vs){
vs.clear();//To erase
ss.clear();
}
}
}
The function eraseSt is called from the client side, passing the name inputed by the user for his record.
You can now play the demo and look more code after.
THIS DEMO USE OUR FLASHCOMM SERVER. IT'S AVAILABLE ONLY A FEW HOURS EACH DAY.SORRY IF IT'S NOT AVAILABLE NOW.
The code in the client side is:
client_nc=new netConnection();
client_nc.connect("rtmp://domain-name/appname");
client_nc.onStatus = function(info) {
if(info.code=="NetConnection.Connect.Success"){
_root.msg.text = "The connection was a success!";
}
else{
_root.msg.text = "Application not available now!";
}
}
// Create output stream
out_ns = new NetStream(client_nc);
sout_ns=new netStream(client_nc); //For sound
// Create input stream
in_ns = new NetStream(client_nc);
Replay_video.attachVideo(in_ns); //Replay video is the name
//of a component Embeded Video
//to play the stream
sin_ns=new netStream(client_nc);
//Attach the camera to another component Embeded Video
client_cam=Camera.get();
Live_video.attachVideo(client_cam);
function doRecord(){ //Click Handler of the button
if(_root.name.text!=""){ //name is the input field
sout_ns.attachAudio(Microphone.get());
//Start publishing the camera output and sound as a recorded streams out_ns.attachVideo(Camera.get());
out_ns.publish("v"+ _root.name.text, "record");
sout_ns.publish("s"+ _root.name.text, "record");
_root.msg.text = _root.name.text+ " recording.Click 'Stop Record' to finish.";
}
else{
_root.msg.text ="You need to type a name...";
}
}
function doStop(){
out_ns.close();
sout_ns.close();
_root.msg.text = _root.name.text+ " recorded.";
}
function doPlay(){
in_ns.play("v"+ _root.name.text);
sin_ns.play("s"+ _root.name.text);
}
function toErase(){
client_nc.call("eraseSt", null,_root.name.text);
_root.msg.text = _root.name.text+ " erased.";
}
//Capturing the end of play
in_ns.onStatus = function(info){
if (info.code == "NetStream.Play.Stop"){
_root.msg.text = _root.name.text+ " finished";
}
}
We don't have a good synchronization between image and sound. Avoid create "close talking head" applications.
At this course we tried to avoid the use of many of the "components" of FlashComm. Doing this we tried that you have a better idea of how the FlashComm works. If a "component" is a solution for your problem, use it.
PREVIOUS LESSON T. CONTENTS HOMEPAGE
