Record audio and video with FluorineFX

Source: Internet
Author: User

To make a complete recording program, the class that handles the RPC request not only inherits Applicationadapter, but also inherits the Istreamservice interface, which defines play (), pause (), publish (), CreateStream ( ) and a series of methods to improve the program

For security, you can customize a class that implements the FluorineFx.Messaging.Api.Stream.IStreamPublishSecurity interface and define a ispublishallowed () method, In this method, the type of the publishing stream, the name of the stream, and the authorization of the publishing stream can be judged. Then rewrite the AppStart () method of the Applicationadapter class and register the security Policy: registerstreampublishsecurity (New publishsecurity ());

The recorded file is saved under Apps/myroom/streams

Recorded by Netstream.publish (Name,type), the parameters are described as follows:

name:string (default = null)-The string that identifies the stream. If False is passed, the publish operation stops. The client that subscribes to this stream must still pass this name when calling Netstream.play (). You do not have to include the file extension in the stream name

type:string (default = NULL)-Specifies how the stream's string is published. Valid values are "record", "Append", and "live". The default value is "Live"

If you pass a record, Flash Player publishes and records real-time data, while saving the recorded data to an FLV file with a name that matches the value passed to the name parameter. This file is saved in a subdirectory of the directory where the server application resides on the server. If the file already exists, the file is overwritten.

If you pass "append", Flash Player publishes and records live data, appending the recorded data to an FLV file with a name that matches the value passed to the name parameter, which is stored in a subdirectory of the directory where the server application resides on the server. If you do not find a file that matches the name parameter, create one.

If this parameter is omitted or "live" is passed, Flash Player publishes live data without recording. If there is a file with a name that matches the value passed to the name parameter, delete it.

Server-side code:

MyVideoApp.cs
class myvideoapp:applicationadapter{    override bool AppStart (FluorineFx.Messaging.Api.IScope application)    {        registerstreampublishsecurity (publishsecurity ());        return base. AppStart (application);    }}

PublishSecurity.cs
Using system;using system.collections.generic;using system.text;using fluorinefx.messaging.api.stream;using Fluorinefx.messaging.api;using Fluorinefx.context;namespace servicelibrary5{ Publicclasspublishsecurity:istreampublishsecurity { PublicBOOL Ispublishallowed (iscope scope, string name, String mode) {//if (! " Live ". Equals (mode))           //{           ////Not a live stream           //return false;           //}if (!"Record". Equals (mode)) {//Not recording streamreturn false;
} iconnection connection = FluorineContext.Current.Connection; if (!"Authenticated". Equals (connection. GetAttribute ("Usertype"))) {//User is not authenticated return false; } if (!name. StartsWith ("Testing"))return false; Elsereturn true; } }}

Client code:

<?xml version="1.0"encoding="Utf-8"? ><mx:application xmlns:mx="Http://www.adobe.com/2006/mxml"layout="Absolute"><mx:uicomponent id="Uibox"Width=" the"height=" the"/><mx:label x="371"y="222"text="Label"Id="Lblmessage"/><mx:button x="371"y=" the"Label="Connect to Server"click="OnConnect ()"/><mx:button x="371"y="94"Label="Start Recording"click="Onstartrecord ()"/><mx:button x="371"y="136"Label="Stop Recording"click="Onstoprecord ()"/><mx:button x="371"y=" the"Label="Play Video"click="Onplayrecord ()"/><mx:script><! [cdata[PrivatevarNc:netconnection;PrivatefunctionOnConnect ():void{NC =NewNetconnection (); Nc.addeventlistener (netstatusevent.net_status,onnetstatus); Nc.connect ("Rtmp://localhost:8323/myvideoroom"); nc.client = this;}PrivatefunctionOnnetstatus (event:netstatusevent):void{if(Event.info.code = ="NetConnection.Connect.Success"){ This. Lblmessage.text ="Connection server succeeded";} else{ This. Lblmessage.text ="Connection Server failed";}}PrivatefunctionOnstartrecord ():void{if(NC) {varNs:netstream =NewNetStream (NC);varMic:microphone = Microphone.getmicrophone ();varCamera:camera = Camera.getcamera (); Ns.attachaudio (MIC); Ns.attachcamera (Camera); Ns.publish ("demo001","Record"); This. Lblmessage.text ="Recording ...";}}PrivatefunctionOnstoprecord ():void{if(NC) {Nc.close (); This. Lblmessage.text ="stopped recording";}}PrivatefunctionOnplayrecord ():void{NC =NewNetconnection (); Nc.addeventlistener (NETSTATUSEVENT.NET_STATUS,ONNETSTATUS2); Nc.connect ("Rtmp://localhost:8323/myvideoroom");}PrivatefunctionOnNetStatus2 (event:netstatusevent):void{if(Event.info.code = ="NetConnection.Connect.Success"){varNs:netstream =NewNetStream (NC);varVideo:video =NewVideo (); Video.attachnetstream (NS); This. Uibox.addchild (video); Ns.play ("demo001");}}]] ></mx:Script></mx:Application>

Record audio and video with FluorineFX

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.