Online Video Recording Using FMS

Source: Internet
Author: User
Preparation tools:

Flash Media Server ..

Flash 8 & flash 8 player (-______-)

One camera and one microphone.
Open flash and create a new flash document.

CTRL + L tune the warehouse... there is a triangle in the upper right corner of the warehouse, click it. Then select "new video element ";

Name: Video

Create two layers in the main scenario: video_record and video_play;

Drag the video components in the library to these two layers. The names are video_r and video_p.video_r. video_p are used to record videos.

(I will not write a new MC or a class name.ProgramIntroduction. If you don't even know the name of MC, I believe you won't understand this tutorial. Sorry !)

Procedure:

VaR server_uri: String = "rtmp: // localhost/tensharp ";
// FMS address;

VaR videoname: String = "keerula ";
// Video name.

VaR my_nc: netconnection = new netconnection ();
// Create a connection object to connect to the FMS;

My_nc.connect (server_uri );
// Connect to the FMS;

VaR my_ns: netstream = new netstream (my_nc );
// Create a stream to capture and play a video;

VaR my_cam: Camera = camera. Get ();
Video_r.attachvideo (my_cam );
// Obtain the image head and load the video obtained by the camera to video_r.

My_cam.setquality (1024, 90 );
// Set the bandwidth and quality;

VaR my_mic: microphone = microphone. Get ();
// Obtain the mic;

My_ns.attachvideo (my_cam );
My_ns.attachaudio (my_mic );
// Load the camera image and MIC sound to the stream.

Video_p. _ visible = false;
// Sets the playback window to invisible.

My_nc.onstatus = function (thisobj: Object)
{
// Trace (thisobj. Code );
If (thisobj. Code = "netconnection. Connect. Success ")
{
Recordstop ("idle ");
// Execute the recording stop method and set the status to idle
}
Else
{
Trace ("error: Server not started or Uri input error .");
}
}
// Onstatus indicates the connection status of the server.

Function record ()
{
Video_r. _ visible = true;
// Set the recording window to visible.
Video_p. _ visible = false;
// Set the playback window to invisible.
My_ns.publish (videoname, "record ");
// The key lies in this sentence. So many records are written around it. Record is recorded.
Streaminfo ("nowrecord ");
// Execute the streaminfo method and set the parameter to nowrecord;
Btn_pr.btn_text.text = "stop ";
// Button text: Stop.
Recordinterval = setinterval (recordtime, 1000 );
// Count the recording time.
}
// Method: recording.

VaR timenum: Number = 0;
// Recording time.

Function recordtime ()
{
Timenum ++;
Txt_status.text = "Recording" + "" + "time:" + math. Floor (timenum/60) + "Minute" + (timenum % 60) + "second ";
}
// Method: recording time statistics.

Function recordstop (_ Status: string)
{
// _ Status indicates the current status text.
Txt_status.text = "Current status:" + _ status;
Btn_pr.btn_text.text = "Recording ";
Streaminfo ("nowstop ");
// Execute the streaminfo method .. and set the parameter to nowstop;
Clearinterval (recordinterval );
Timenum = 0;
// No records are recorded. Clear the statistical time.
If (_ Status = "Recording completed ")
{
Finished ();
}
// This should be skipped ..
}
// Method: idle or recording completed.

Function finished ()
{
My_ns.close ();
// The recording is finished. Close the recording.
VaR thisobj = this;
VaR finishalert: movieclip = _ root. attachmovie ("alert", "finishalert", 100 );
// This is a pop-up box. For details, refer to MC: alert in the library.
With (finishalert)
{
Alerttitle.html = true;
Alerttitle.html text = "" + "Recording completed! "+ "";
Info. Text = "Recording completed... Please select next operation ."
_ 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 = "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 as non-vertex.
}
// Method: the recording is complete.

Function closealert (_ alert: movieclip)
{
Btn_pr.enabled = true;
Unloadmovie (_ alert );
}
// Disable the alert instance.

function streaminfo (_ Status: string)
{< br> btn_pr.onrelease = function ()
{< br> If (_ Status = "nowrecord")
{< br> recordstop ("Recording completed ");
}< br> else if (_ Status = "nowstop")
{< br> record ();
}< br> else if (_ Status = "nowplay")
{< br> record ();
}< BR >}< br> // .. if you read the above carefully, you don't need to say that.

Function playvideo ()
{
Txt_status.text = "Current status:" + "playing ...";
Streaminfo ("nowplay ")
Video_r. _ visible = false;
Video_p. _ visible = true;
Video_p.attachvideo (my_ns );
// Load the video to the playing window.
My_ns.play (videoname );
// Start playing.
Btn_pr.btn_text.text = "record ";
My_ns.onstatus = function (playinfo)
{
If (playinfo. Code = "netstream. Play. Stop ")
{
My_ns.seek (0 );
My_ns.pause ();
Txt_status.text = "Current status:" + "playback completed ...";
}
}
// Stream status information... trace (playinfo. Code) for details );
}
// Method: play the video.
// Note that you do not need to write the path when playing the video with the FMS, because the videos recorded by the FMS are directly stored in the default stream file directory of the FMS.
// The path for storing the recorded video: the installation directory of the FMS:/application/site/streams/_ definst _

If you have read the above, you can do it yourself. Good luck (by: keerula )(:
For details about MC, see the FLA file.
: Http://www.cincn.com/attachments/month_0606/e200662103113.rar
Note: This tutorial and the accompanying source files are only for personal communication and usage by netizens. Do not use them for commercial purposes. Please contact the commercial version separately.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.