1,服务器端可以空实现ApplicationAdapter:示例如下:
- package org.chy.flex01;
- import org.red5.server.adapter.ApplicationAdapter;
- public class Application extends ApplicationAdapter{
- }
客户端使用Flex实现摄像头获取视频并发布代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
- <mx:Script>
- <!--[CDATA[
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.NetStatusEvent;
- import mx.controls.Alert;
- private var nc:NetConnection;
- private var ns:NetStream;
- private var cam:Camera;
- private function init():void{
- nc = new NetConnection();
- nc.addEventListener(NetStatusEvent.NET_STATUS,connectServerHander);
- nc.client = this;
- nc.connect("rtmp://58.116.56.68:1935/Flex01");
- }
- private function connectServerHander(evt:NetStatusEvent):void{
- trace(evt.info.code);
- cam = Camera.getCamera();
- if(cam != null){
- cam.setMode(313,194,30);
- cam.setQuality(0,70);
- ns = new NetStream(nc);
- ns.attachCamera(cam);
- ns.publish("red5");
- var vi:Video = new Video();
- vi.width = 313;
- vi.height = 194;
- vi.attachCamera(cam);
- videoDisplay.addChild(vi);
- }else{
- Alert.show("no Camera");
- }
- }
- public function onBWDone():void{
- }
- ]]-->
- </mx:Script>
- <mx:VideoDisplay x="162" y="77" width="313" height="194" id="videoDisplay"/>
- </mx:Application>
客户端使用Flex play视频代码如下:
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
- <mx:Script>
- <!--[CDATA[
- import flash.display.*;
- import flash.utils.*;
- import flash.events.*;
- import flash.net.*;
- import flash.media.Video;
- import flash.media.Camera;
- private var nc:NetConnection;
- private function init():void{
- nc = new NetConnection();
- nc.connect("rtmp://58.116.56.68:1935/Flex01");
- nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
- }
- private function connectHandler(evt:NetStatusEvent):void{
- var ns:NetStream = new NetStream(nc);
- var video:Video=new Video() ;
- video.width = 313;
- video.height = 194;
- video.attachNetStream(ns);
- ns.play("red5");
- videoDisplay.addChild(video);
- }
- ]]-->
- </mx:Script>
- <mx:Panel x="132" y="78" width="356" height="266" layout="absolute" title="现场直播" fontSize="14">
- <mx:VideoDisplay x="10" y="10" width="320" height="193" id="videoDisplay"/>
- </mx:Panel>
- </mx:Application>