Video Recording: <? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" Height = "312" width = "328" creationcomplete = "Init ()"> <mx: SCRIPT> <! [CDATA [// pre-defined declaration import MX. controls. alert; import MX. events. sliderevent; // create a basic network connection object private var VI: Video; private var cam: Camera; // define a camera private var inns: netstream; private var outns: netstream; private var NC: netconnection; // Private var mic: microphone; // defines a microphone private VaR _ duration: Number; // specifies the video playback time private var playposition: number; // define the playback progress position // Private var soundposition: Number; // define the sound Size Control bar Private var flag: Boolean = false; private var lastvideoname: String = ""; // The Name Of The Private VaR _ URL: String = "rtmp: // 127.0.0.1: 1935/videorec "; Public Function Init (): void {setupcamera (); // initialize camera information} // start recording and click public function clickconnect (): void {NC = new netconnection (); NC. addeventlistener (netstatusevent. net_status, nshandler); NC. connect (_ URL); // connect to the red5 server} public function nshandler (EVT: Netstatusevent): void {If (evt.info. code = "netconnection. connect. success ") {// If the connection is successful playclick ();} else {alert. show ("connection failed") ;}// start recording public function playclick (): void {If (Vi! = NULL) {vi. clear (); vdisplay. removechild (VI); VI = new video (); VI. width = 320; VI. height = 240; VI. attachcamera (CAM); vdisplay. addchild (vi) ;}outns = new netstream (NC); outns. attachcamera (CAM); // Save the camera to outns // outns. attachaudio (MIC); // Save the microphone to outns lastvideoname = "red5recorddemo _" + math. random () + gettimer (); outns. publish (lastvideoname, "record"); startrec. enabled = false; stoprec. enabled = true ;} // Stop recording public function stopclick (): void {// close the connection outns between ns and red5. close (); VI. clear (); vdisplay. removechild (VI); // lock the start button to make it take effect startrec. enabled = true; // lock the stop button to invalidate stoprec. enabled = false;} // play the public function playlastvideo (): void {If (NC! = NULL) {// addeventlistener (event. enter_frame, onenterframe); inns = new netstream (NC); // defines onmetadata to obtain video-related data var customclient: Object = new object (); customclient. onmetadata = function (metadata: Object): void {_ duration = metadata. duration; // get the video duration t_sh.maximum = _ duration;} inns. client = customclient; // Delete the original _ localvideo, which facilitates switching between recording and playing the video Vi = new video (); VI. width = 320; VI. height = 240; VI. attachnet Stream (INNS); vdisplay. addchild (VI); inns. play (lastvideoname + ". FLV "); addeventlistener (event. enter_frame, onenterframe) ;}/// initialize the public function setupcamera (): void {// start the camera cam = camera. getcamera (); If (Cam! = NULL) {cam. addeventlistener (statusevent. status, onstatushandler); cam. setmode (320,240, 30); cam. setquality (); // sets the definition Vi = new video (); VI. width = 320; VI. height = 240; VI. attachcamera (CAM); vdisplay. addchild (VI);} // MIC = microphone. getmicrophone (); // If (mic! = NULL) {// mic. setsilencelevel (0,-1); // sets the microphone to remain active and continuously receives audio data from the set. // mic. gain = 80; // set the microphone sound size //} private function onstatushandler (Event: statusevent): void {If (! Cam. muted) {// determines whether the camera exists startrec. Enabled = true;} else {alert. Show ("error: unable to link to the active camera! ")} Cam. removeeventlistener (statusevent. status, onstatushandler);} public function thumbpress (Event: sliderevent): void {inns. togglepause (); removeeventlistener (event. enter_frame, onenterframe);} private function thumbchanges (Event: sliderevent): void {playposition = t_sh.value; // the position of the current playback video progress = Inns of the current playback progress bar. seek (playposition); addeventlistener (event. enter_frame, onenterframe);} private function thumb Release (Event: sliderevent): void {// After the mouse is released, execute inns. seek (playposition); // locate the inns position of the current progress bar. togglepause (); addeventlistener (event. enter_frame, onenterframe);} public function onenterframe (Event: Event): void {If (_ duration> 0 & inns. time> 0) {// if the video time and playing time are greater than 0 t_sh.value = inns. time; lbtime. TEXT = formattimes (inns. time) + "/" + formattimes (_ duration);} If (formattimes (inns. time) = formattimes (_ dura Tion) {// If the playback is complete, the streaming is closed, and the label if (flag = true) of the placement time is initialized {// if it is loaded, not executed | false indicates loading, and true indicates that removeeventlistener (event. enter_frame, onenterframe); inns. close (); lbtime. TEXT = "/" + formattimes (_ duration);} setTimeout (function (): void {flag = true ;}, 1000 );}} // time format operation private function formattimes (value: INT): String {var result: String = (Value % 60 ). tostring (); If (result. length = 1) {result = math. Floor (value/60 ). tostring () + ": 0" + result;} else {result = math. floor (value/60 ). tostring () + ":" + result;} return result;} // audio volume control // Private function sound_thumbchanges (Event: sliderevent): void {// soundposition = th_sound.value; /// private function sound_thumbrelease (Event: sliderevent): void {// vdisplay. volume = soundposition; //}]> </MX: SCRIPT> <mx: videodisplay x = "0" Y = "0" wi DTH = "324.5" Height = "240" id = "vdisplay"/> <mx: button x = "10" Y = "250" label = "Start recording" id = "startrec" Click = "clickconnect ()" enabled = "false"/> <mx: button x = "10" Y = "280" label = "stop recording" width = "70" id = "stoprec" Click = "stopclick () "enabled =" false "/> <mx: button x =" 253 "Y =" 268 "label =" play "Click =" playlastvideo () "/> <mx: hslider x = "98" Y = "248" width = "143" id = "t_sh" thumbpress = "thumbpress (event)" thumbrelease = "thu Mbrelease (event) "change =" thumbchanges (event) "/> <mx: label x = "237" Y = "242" text = "0: 00/0: 00" width = "89" textalign = "center" Height = "18" id = "lbtime"/> <! -- Mx: hslider x = "98" Y = "278" width = "91" id = "th_sound" minimum = "0" Maximum = "1" value = "{vdisplay. volume} "change =" sound_thumbchanges (event) "thumbrelease =" sound_thumbrelease (event) "/> <mx: label x = "187" Y = "270" text = "sound" Height = "20" width = "44" textalign = "center"/--> </MX: application> Note: 1. red5 serves as a server, followed Code In fact, there is nothing. The most important thing is the front-end flex code. Of course, there are still some configuration problems. I believe my friends who have done red5 simple demo should know that I will not go into detail here. 2. Article The note is the recording of the audio. The screen is dropped because there is no microphone on the local machine. If you want to add some features, just remove the comments. 3. The following figure shows the front-end player. <? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" width = "835" Height = "782"> <mx: SCRIPT> <! [CDATA [import MX. events. sliderevent; // here is the class required for import. With the import keyword, there is nothing to say about import MX. events. videoevent; import flash. events. keyboardevent; import MX. controls. alert; import flash. display. stage; private var soundposition: Number; // customizes A playingmove () function. function: When a video is played, the value of the hslider control with ID "my_hs" is the video playback time, and the maximum value is the total length of the video private function playingmove (Event: videoevent): void {my_hs.value = flvideo. playheadtime; My_hs.maximum = flvideo. totaltime;} // custom hs_onchange () function. function: when you drag the hslider control to change its value, the video playback header is in its value, private function hs_onchange (Event: sliderevent): void {flvideo. playheadtime = event. value;} // stop the private function stopmovie (Event: mouseevent): void {flvideo. stop () ;}// play private function playmovie (Event: mouseevent): void {playurl (urltext. text);} // pause private function pausemovie (E Vent: mouseevent): void {flvideo. pause ();} // drop-down box private function onchangeurl (Event: keyboardevent): void {trace (event. keycode); If (event. keycode = 13) {playurl (urltext. text) ;}} private function playurl (URL: string): void {If (flvideo. playing) flvideo. stop (); flvideo. source = URL; flvideo. play ();} // audio volume control private function sound_thumbchanges (Event: sliderevent): void {soundposition = hs_sound.value ;} Private function sound_thumbrelease (Event: sliderevent): void {flvideo. volume = soundposition;} // formatting time private function formattimes (value: INT): String {var result: String = (Value % 60 ). tostring (); If (result. length = 1) {result = math. floor (value/60 ). tostring () + ": 0" + result;} else {result = math. floor (value/60 ). tostring () + ":" + result;} return result;} private function displaystatecha Nge (): void {If (displaychk. selected) {stage. displaystate = "fullscreen";} else {stage. displaystate = "normal" ;}}]]> </MX: SCRIPT> <mx: XML id = "xmldata" Source = "flvdata. XML "format =" XML "/> <mx: videodisplay id =" flvideo "playheadupdate =" playingmove (Event) "x =" 10 "Y =" 10 "autoplay =" false "buffertime =" 0.5 "maintainaspectratio =" false "width =" 294 "Height =" 219 "/> <MX: controlbar id = "ctrlbar" x = "10" Y = "237" W Idth = "545" Height = "52"> <mx: textinput id = "urltext" width = "150" keyup = "onchangeurl (Event) "fontfamily =" Arial "fontsize =" 12 "color =" # 2c2b3a "enabled =" true "Height =" 26 "tooltip =" Enter the network address of the FLV file "/> <mx: button label = "play" Click = "playmovie (event)"/> <mx: button label = "stop" Click = "stopmovie (event)"/> <mx: button label = "pause" Click = "pausemovie (event)"/> </MX: controlbar> <mx: controlbar id = "ctrlbar0" x = "10" Y = "297" width = "545" Height = "52"> <mx: Label text = "volume" color = "# ffffff"/> <! -- Player sound control --> <mx: hslider id = "hs_sound" width = "80" minimum = "0" Maximum = "1" thumbrelease = "sound_thumbrelease (Event) "Change =" sound_thumbchanges (event) "value =" {flvideo. volume} "/> <mx: checkbox id =" displaychk "label =" Full Screen mode "change =" displaystatechange () "/> </MX: controlbar> <mx: controlbar id = "ctrlbar1" x = "10" Y = "357" width = "545" Height = "52"> <mx: label x = "480" Y = "341" id = "Playtime" text = "{formattimes (FLV IDEO. playheadtime) }:{ formattimes (flvideo. totaltime)} "color =" # ffffff "/> <mx: hslider minimum =" 0 "id =" my_hs "change =" hs_onchange (Event) "width =" 179 "/> </MX: controlbar> </MX: Application> PLAYER 2: <? XML version = "1.0" encoding = "UTF-8"?> <Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "vertical"> <mx: SCRIPT> <! [CDATA [/** Cato Paus skrede umbrellacorp da **/[Bindable] private var movie: string; Private function setsource (): void {// movie = "http://stage.orchestra.it/x.flv "; // some dud dancing 16 min sample. movie = "http: // 58.211.20.8/v2blog/2007/03/31/1175351546716 -converted.flv"; // the URL of the FLV ver. 1.1 do contains the metadata for totaltime FLV ver 1.0 do's not. /* if you type the URL into videodisplay. source and use autoplay it starts to play in design mode that's realy annoying. */} private function formatpositiontooltip (value: INT): String {// do only handle minuts. vaR result: String = (Value % 60 ). tostring (); If (result. length = 1) {result = math. floor (value/60 ). tostring () + ": 0" + result;} else {result = math. floor (value/60 ). tostring () + ":" + result;} return result;}]> </MX: SCRIPT> <mx: panel layout = "absolute" width = "400" Height = "400" headerheight = "0" cornerradius = "2" borderstyle = "solid" borderthickness = "0" borderthicknessbottom = "0 ""borderthicknessleft =" 0 "borderthicknessright =" 0 "borderthicknesstop =" 0 "backgroundcolor =" #000000 "> <mx: videodisplay id = "videodisplay" Source = "{movie}" width = "380" Height = "310" Left = "10" Top = "10"/> <mx: progressbar id = "loadprogress" label = "" mode = "Event" barcolor = "#00ff00" minimum = "0" Maximum = "100" Y = "336" Height = "20 "Source =" {videodisplay} "trackheight =" 10 "trackcolors =" [#00ff00, # e6eeee] "Left =" 10 "Right =" 10 "/> <mx: hslider id =" position "Height =" 5 "datatipformatfunction =" formatpositiontooltip "thumbpress =" videodisplay. pause () "slideduration =" 0 "thumbrelease =" videodisplay. play () "change =" videodisplay. playheadtime = position. value "value =" {videodisplay. playheadtime} "minimum =" 0 "Maximum =" {videodisplay. totaltime} "Left =" 4 "Right =" 4 "Bottom =" 62 "/> <mx: button label =" play "Click =" videodisplay. play (); "cornerradius =" 0 "Bottom =" 10 "x =" 10 "/> <mx: button label =" pause "Click =" videodisplay. pause (); "cornerradius =" 0 "Bottom =" 10 "Left =" 69 "/> <mx: button label =" stop "Click =" videodisplay. stop (); "cornerradius =" 0 "Left =" 138 "Bottom =" 10 "/> <mx: hslider id = "volume" snapinterval = "0.01" value = "0.5" Maximum = "1.0" change = "videodisplay. volume = volume. value; "livedragging =" true "Height =" 20 "Left =" 236 "Bottom =" 20 "width =" 154 "/> <mx: label stylename = "playheadtimelabel" text = "{formatpositiontooltip (videodisplay. playheadtime)}-{formatpositiontooltip (videodisplay. totaltime)} "color =" # ffffff "Left =" 5 "Top =" 0 "/> </MX: Panel> <mx: button click =" setsource () "label =" Get FLV "/> </MX: Application> this article from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/lentonnet/archive/2007/11/08/1873463.aspx control volume is a little simple, but can realize the function is enough. with the jslider of aswing, you must configure the aswing class library before using it. package {import flash. display. sprite; import flash. media. soundmixer; import flash. media. soundtransform; import Org. aswing. jslider; import Org. aswing. event. interactiveevent ;/***... * @ low B students 2009 */public class soundvolumeslider extends sprite {public var jsld: jslider = new jslider (100,100,); Public Function soundvolumeslider (): void {jsld. width = 100; jsld. height = 20; addchild (jsld); jsld. addstatelistener (onsldchange);} private function onsldchange (E: interactiveevent): void {var val: Int = (e.tar get as jslider ). getvalue (); var numval: Number = Val/100; If (E. isprogrammatic () = false) {// manually change var TSF: soundtransform = new soundtransform (numval); soundmixer. soundtransform = TSF ;}}}}
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.