发布端
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="800" height="600"
creationComplete="init()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var nc:NetConnection;
private var ns:NetStream;
private var camera:Camera;
private var microphone:Microphone;
private var video:Video;
private var h264:H264VideoStreamSettings = new H264VideoStreamSettings();
private function init():void
{
initCameraAndMicrophone();
}
private function initNet():void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/testH264");
nc.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
nc.client = this;
}
private function initCameraAndMicrophone():void
{
camera = Camera.getCamera();
microphone = Microphone.getMicrophone();
trace(camera);
if(Camera.isSupported)
{
if(camera)
{
if(camera.muted)
{
camera.addEventListener(StatusEvent.STATUS,cameraStatusEventHandler);
camera.addEventListener(ActivityEvent.ACTIVITY,activityEventHandler);
}
camera.setMode(320,240,15);
video = new Video();
video.smoothing = true;
video.attachCamera(camera);
this.videodisplay.addChild(video);
}
else
{
trace("No Camera is installed.")
}
}
}
private function onStatusEvent(event:NetStatusEvent):void
{
trace(event.info.code);
var code:String = event.info.code;
switch(code)
{
case "NetConnection.Connect.Success":
creatStream();
break;
}
}
private function cameraStatusEventHandler(event:StatusEvent):void
{
trace(event.code);
switch(event.code){
case "Camera.Muted":
break;
case "Camera.Unmuted":
initNet();
break;
}
}
private function activityEventHandler(event:ActivityEvent):void
{
}
private function creatStream():void
{
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
var h264Stream:H264VideoStreamSettings = new H264VideoStreamSettings();
h264Stream.setProfileLevel(H264Profile.BASELINE,H264Level.LEVEL_5_1);
h264Stream.setMode(1280,720,25);
h264Stream.setQuality(0,80);
ns.videoStreamSettings = h264Stream;
ns.attachCamera(camera);
ns.attachAudio(microphone);
ns.publish("mp4:testH264_1.mp4","record");
}
private function onMetaDataHandler(info:Object):void
{
}
]]>
</fx:Script>
<s:Videodisplay id="videodisplay" width="320" height="240" horizontalCenter="0"
verticalCenter="0"/>
</s:Application>
接收端
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="800" height="600"
creationComplete="init()">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private var nc:NetConnection;
private var ns:NetStream;
private var camera:Camera;
private var microphone:Microphone;
private var video:Video;
private var h264:H264VideoStreamSettings = new H264VideoStreamSettings();
private function init():void
{
//initCameraAndMicrophone();
initNet();
}
private function initNet():void
{
nc = new NetConnection();
nc.connect("rtmp://localhost/testH264");
nc.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
nc.client = this;
}
private function onStatusEvent(event:NetStatusEvent):void
{
trace(event.info.code);
var code:String = event.info.code;
switch(code)
{
case "NetConnection.Connect.Success":
creatStream();
break;
}
}
private function creatStream():void
{
var nsClient:Object = {};
nsClient.onMetaData = onMetaDataHandler;
ns = new NetStream(nc);
ns.client = nsClient;
ns.addEventListener(NetStatusEvent.NET_STATUS,onStatusEvent);
ns.play("mp4:testH264_1.mp4");
video = new Video(320,240);
video.attachNetStream(ns);
this.videodisplay.addChild(video);
}
private function onMetaDataHandler(info:Object):void
{
trace(info.duration);
}
]]>
</fx:Script>
<s:Videodisplay id="videodisplay" width="320" height="240" horizontalCenter="0"
verticalCenter="0"/>
</s:Application>
FMS服务器最好是4.5版本,
在应用服务器里面(application目录)新建一个testH264目录即可。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。