一段获取视频的简易方法

<?xml version="1.0" encoding="utf-8"?>
<!--

//
// Copyright (C) 2007 royllik.
//通用视频组件,有local和remote两种状态,这里的代码不需要修改
//

-->
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml"
styleName="opaquePanel" layout="absolute"
title="{thisTitle}"
horizontalScrollPolicy="off" verticalScrollPolicy="off">

<mx:Script>
<![CDATA[
import flash.external.ExternalInterface;
import mx.controls.Alert;
import mx.core.UIComponent;
import mx.managers.PopUpManager;
import flash.media.*;
import avchat.chatRoom.utils.ModelLocator;
import avchat.chatRoom.ui.event.CustomEvent;
private var model:ModelLocator = ModelLocator.getInstance();


[Bindable]
public var thisTitle:String;

public var reciveStream:String;

private var camera:Camera;
private var mic:Microphone;
private var outns:NetStream;
private var inns:NetStream;


private var video:Video;
private var videoHolder:UIComponent;


protected override function createChildren():void {
super.createChildren();
this.titleBar.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
this.titleBar.addEventListener(MouseEvent.MOUSE_UP, onUp);

}

private function onDown(evt:Event):void
{
this.startDrag();
}
private function onUp( evt:Event ):void
{
this.stopDrag();
}


//断开流媒体连接,并删除videoHolder
public function stopAv():void
{
if(outns)
{
//outns.pause();
outns.close();
//Alert.show("关闭了" + outns);
}
if(inns)
{
//inns.pause();
inns.close();
//Alert.show("关闭了" + inns);
}
if(video)
video.clear();
this.removeAllChildren();

//this.removeChild(videoHolder);
thisTitle = "";
}


//设置麦克风
private function setmic():void
{
mic.gain = 70;
mic.rate = 11;
mic.setUseEchoSuppression(true);
mic.setSilenceLevel(5, 1000);
//mic.setLoopBack(false);

}

//设置摄像头
private function setCam():void
{
camera.setKeyFrameInterval(30);
camera.setMode(320, 240, 25, true);
camera.setQuality(0,85);
//camera.setLoopback(true);
}

//推送自己的流媒体
public function publishAV(recordorlive:String, width:int, height:int):void
{
//发送视频,视频的名字是 发送人的ID+_+当前ROOM的名字
var streamName:String = model.myself.userId + "_" + model.currentRoom;
//trace("streamName:" + streamName);
if(outns)
outns.close();
outns = new NetStream(model.fmsserver.nc);
outns.client = this;
//outns.checkPolicyFile = true;
if (Camera.names.length > 0){
camera = Camera.getCamera();
}
//trace(camera);
if (camera == null)
{
mic = Microphone.getMicrophone();
setmic();

outns.attachAudio(mic);
//这里要以后要根据要求,决定是否录制
//Alert.show("streamName:"+ streamName);
outns.publish(streamName, recordorlive);

}
else
{
mic = Microphone.getMicrophone();
setmic();
setCam();
outns.attachAudio(mic);
outns.attachCamera(camera);
//这里 要以后要根据要求,决定是否录制
outns.publish(streamName, recordorlive);
//Alert.show("streamName:"+ streamName);

}
//Alert.show("自己发送" + streamName);
videoHolder = new UIComponent();
videoHolder.setActualSize(width,height);
video = new Video(width, height);
video.attachCamera(camera);
videoHolder.addChild(video);
this.addChild(videoHolder);

}
//接收视频,视频的名字是 发送人的ID+_+当前ROOM的名字
public function reciveAV(width:int,height:int):void
{
//trace(this.reciveStream);
//var reciveStream:String = thisUserId + "_" + model.currentRoom;
//Alert.show("reciveStream: "+reciveStream);
if(inns) inns.close();
inns = new NetStream(model.fmsserver.nc);
//inns.checkPolicyFile = true;
inns.play(reciveStream);
//Alert.show("收到了" + reciveStream);
inns.client = this;
videoHolder = new UIComponent();
videoHolder.setActualSize(width,height);
video = new Video(width, height);
video.attachNetStream(inns);
videoHolder.addChild(video);
this.addChild(videoHolder);
}


]]>
</mx:Script>
</mx:Panel>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值