Flash采集音频和视频发布到red5服务器

直接上代码,不解释。

import flash.display.MovieClip;
import flash.events.*;
import flash.media.Camera;
import flash.media.Microphone;


import flash.media.Video;
import flash.media.SoundCodec;
import flash.net.NetStream;
import flash.net.NetConnection;
import flash.display.StageAlign;
import flash.display.StageScaleMode;


var resp:Responder = new Responder(onResult);
var _video:Video;
var _cam:Camera;
var _mic:Microphone;
var _nc:NetConnection;
var _ns:NetStream;




stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
createChildren();
initConn();




function createChildren():void
{
_cam = Camera.getCamera();
_cam.setQuality(144000, 85);
_cam.setMode(320, 240, 15);
_cam.setKeyFrameInterval(60);
_video=new Video();
_video.attachCamera(_cam);
addChild(_video);
_mic = Microphone.getMicrophone();
if (_mic != null)
{
_mic.setSilenceLevel(0,-1);
_mic.gain = 80;
_mic.setLoopBack(true);
}
}


function initConn():void
{
_nc=new NetConnection();
_nc.objectEncoding = ObjectEncoding.AMF3;
_nc.client = this;
_nc.addEventListener(NetStatusEvent.NET_STATUS , netStatus);
_nc.connect("rtmp://10.1.49.137/oflaDemo",true);
}


function publish():void
{
var flvName:String = loaderInfo.parameters.videokey;
if (_nc.connected)
{
_ns = new NetStream(_nc);
_ns.addEventListener(NetStatusEvent.NET_STATUS , netStatus);
_ns.attachCamera(_cam);
_ns.attachAudio(_mic);
_ns.publish(flvName, "live");
}
}


function netStatus(event:NetStatusEvent):void
{
if (event.info.code == "NetConnection.Connect.Success")
{
publish();
}
}
function onResult(obj:Object):void
{


}


function getInfor(reobj:Object):void
{
trace("Server returning Infor: "+reobj);
}
function onState(err:Object):void
{
trace("Connection result error: "+err);
}

你可能感兴趣的:(function,object,video,Flash,CAM,returning)