Tutorials | online
Preparation Tool:
Flash Media Server.
Flash 8 && Flash 8 Player
A camera, a mike.
Open Flash and create a new flash document.
CTRL + L pull up library. There is a triangle in the upper-right corner of the library. Then select "New video symbol";
Name is: Video
New 2 layers in the home scene, one named Video_record, the other called Video_play;
Drag the video components from the library to the 2 layers. The name Video_r and Video_p.video_r are used to record video. Video_p is used for video.
(Starting with the new MC Ah, or naming a class I will not write.) only to introduce the program. If you do not know the name of the MC can not understand this tutorial. Everyone forgive me:)
Program section:
var server_uri:string = "Rtmp://localhost/tensharp";
FMS address;
var videoname:string = "Keerula";
The video name.
var my_nc:netconnection = new Netconnection ();
A new Connection object is used to connect the FMS;
My_nc.connect (Server_uri);
Connect FMS;
var my_ns:netstream = new NetStream (MY_NC);
Create a new stream to capture and play the video;
var My_cam:camera = Camera.get ();
Video_r.attachvideo (My_cam);
Get the image head and load the video from the camera into the video_r.
My_cam.setquality (1024, 90);
Set bandwidth and quality;
var my_mic:microphone = Microphone.get ();
Get mic;
My_ns.attachvideo (My_cam);
My_ns.attachaudio (my_mic);
Mount the camera image and mic sound to the stream.
Video_p._visible = false;
Sets the playback window to be invisible.
My_nc.onstatus = function (thisobj:object)
{
Trace (Thisobj.code);
if (Thisobj.code = = "NetConnection.Connect.Success")
{
Recordstop ("idle");
Executes the recording stop method. and set the status to idle
}
Else
{
Trace ("Error: Server not started or URI input error.");
}
}
Onstatus here refers to the connection status of the server.
function record ()
{
Video_r._visible = true;
Sets the recording window to be visible.
Video_p._visible = false;
The playback window is set to not visible.
My_ns.publish (Videoname, "record");
That's the point. wrote so many all around it. The record is a recording.
Streaminfo ("Nowrecord");
Executes the Streaminfo method and sets the parameter to Nowrecord;
Btn_pr.btn_text.text = "Stop";
Button text: Stop.
Recordinterval = SetInterval (recordtime, 1000);
Statistics recording time.
}
Methods: Recording.
var timenum:number = 0;
Recording time.
function Recordtime ()
{
Timenum + +;
Txt_status.text = "is recording" + "" + "Time:" + Math.floor (TIMENUM/60) + "min" + (timenum% 60) + "seconds";
}
Methods: Record time statistics.
function Recordstop (__status:string)
{
__status is the current state text.
Txt_status.text = "Current state:" + __status;
Btn_pr.btn_text.text = "Recording";
Streaminfo ("Nowstop");
Execute Streaminfo Method ... and setting the parameter to Nowstop;
Clearinterval (Recordinterval);
Timenum = 0;
No record. We need to empty the statistic time.
if (__status = "Recording Complete")
{
Finished ();
}
I'm not supposed to say this.
}
Method: Idle or recording complete.
function finished ()
{
My_ns.close ();
It's done. The recording will be turned off.
var thisobj = this;
var finishalert:movieclip = _root.attachmovie ("Alert", "Finishalert", 100);
This is a pop-up box. Specifically look at the Mc:alert in the library.
With (Finishalert)
{
Alerttitle.html = true;
Alerttitle.htmltext = "" +" recording complete! "+"";
Info.text = "Recording complete ... Please select the next action.
_x = video_r._x + (video_r._width-_width)/2;
_y = video_r._y + (video_r._height-_height)/2;
Btn_sub.btn_txt.text = "Play";
Btn_cln.btn_txt.text = "re-record";
Btn_sub.onrelease = function ()
{
Thisobj.playvideo ();
Thisobj.closealert (Finishalert);
}
Btn_cln.onrelease = function ()
{
Thisobj.record ();
Thisobj.closealert (Finishalert);
}
Closed.onrelease = function ()
{
Thisobj.closealert (Finishalert);
}
}
btn_pr.enabled = false;
Set the button to not point.
}
Method: Recording completed.
function Closealert (__alert:movieclip)
{
Btn_pr.enabled = true;
Unloadmovie (__alert);
}
Close that alert.
function Streaminfo (__status:string)
{
Btn_pr.onrelease = function ()
{
if (__status = = "Nowrecord")
{
Recordstop ("recording completed");
}
else if (__status = "Nowstop")
{
Record ();
}
else if (__status = "Nowplay")
{
Record ();
}
}
}
Hey.. If you take a closer look at it, I don't need to tell you that. ^_^
function PlayVideo ()
{
Txt_status.text = "Current state: +" is playing ... ";
Streaminfo ("Nowplay")
Video_r._visible = false;
Video_p._visible = true;
Video_p.attachvideo (My_ns);
Load the video into the playback window.
My_ns.play (Videoname);
Start playing.
Btn_pr.btn_text.text = "re-record";
My_ns.onstatus = function (playinfo)
{
if (Playinfo.code = = "NetStream.Play.Stop")
{
My_ns.seek (0);
My_ns.pause ();
Txt_status.text = "Current state: +" playback complete ... "
}
}
Flow state information ... Detailed please own trace (playinfo.code);
}
Method: Play video.
Note that there is no need to write the path when playing with FMS. Because the video of FMS is directly present in the default stream file directory of FMS.
Storage path for recorded video: FMS installation directory:/application/site/streams/_definst_
If you look like this, you can do it yourself. Good luck, everybody.