Second Physical Communication Laboratory

Showcase

The simple Vide Chat on Flex3

by admin on 3 月.29, 2010, under ASP, Adobe Flex3, Showcase

I described the program of a very simple video chat out with Flex3 and Red5.

Donwload Flex3 source on FlashDevelop 3.0 here

Download Red5 source and Webapp. here

mxml : main.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="init()"
layout="absolute">

<mx:Script>
<![CDATA[
public var myCameraView:mystreaming = new mystreaming();
private var con:ChatConnection;
private var streamingURL:String = "rtmp://192.168.116.128/buruburu";
private var channetKey:String = "demo";
public function init():void {
con = new ChatConnection();
Textframe.addChild(con.logtext);
}
private function connect_chat():void {
if (connectOpen.label == "公開開始") {
cameraview.attachCamera(myCameraView.myLocalvideo.myCamera);
myCameraView.channetKey = channetKey;
myCameraView.connect_chat();
con.close();
connectOpen.label = "公開中止";
}else {
myCameraView.disconnect_chat();
con.close();
connectOpen.label = "公開開始";
}
}
private function shuffle_chat():void {
var myGuseView:gueststreaming = new gueststreaming();
myGuseView.channetKey = channetKey;
myGuseView.playVideo();
streamview.addChild(myGuseView.video);
con.connect(streamingURL);
}
private function sendMsg():void {
con.call("writeText", null, message.text);
message.text = "";
}
]]>
</mx:Script>
<mx:Panel id="VideoPanel" title="Bijo Chat" backgroundColor="0xb1bfc5" >
<mx:HBox  id="Menuframe">
<mx:Button id="connectOpen" x="0" y="0" label="公開開始"  fontSize="10" click="connect_chat()" visible="true" textRollOverColor="0xdeb700" />
<mx:Button id="connectClose" x="100" y="0" label="シャッフル" fontSize="10" click="shuffle_chat()"  visible="true" textRollOverColor="0xdeb700"/>
</mx:HBox>
<mx:HBox  id="Hframe">
<mx:VBox  id="Videoframe">
<mx:VideoDisplay x="0" y="0" width="320" height="180" id="streamview"  visible="true" backgroundImage="@Embed('iphone-camera-icon.jpg')"/>
<mx:VideoDisplay x="0" y="10" width="320" height="180" id="cameraview"  visible="true" backgroundImage="@Embed('iphone-camera-icon.jpg')"/>
</mx:VBox>
<mx:VBox  id="Textframe">
<mx:TextInput id="message" width="100%" enter="sendMsg()" />
</mx:VBox>
</mx:HBox>
</mx:Panel>
</mx:Application>

AS:mystreaming.as

package
{
import flash.media.Video;
import flash.net.NetConnection;
import flash.media.Camera;
import flash.media.Microphone;
import flash.net.NetStream;
import flash.events.*;
import mx.accessibility.AccImpl;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.events.NetStatusEvent;
import flash.events.EventDispatcher;
import mx.controls.Alert;
import mx.events.SliderEvent;
import mx.controls.sliderClasses.Slider;
import mx.rpc.events.ResultEvent;
import mx.managers.PopUpManager;
import mx.core.IFlexDisplayObject;
import mx.collections.ArrayCollection;
/**
* ...
* @author yuucha
*/
public class mystreaming
{
public var counter:Number = 0;
private var pub_nc:NetConnection;
private var pub_ns:NetStream;

private var streamingURL:String = "rtmp://192.168.116.128/buruburu";
private var play_nc:NetConnection;
private var play_ns:NetStream;
private var stat:Number;
private  var clientID:Number;
private var StreamingCamera:Camera;
private var StreamingMic:Microphone;
public var myLocalvideo:myvideo;
public var video:Video = new Video(320, 180);
public var channetKey:String = "";

public function mystreaming():void
{
myLocalvideo = new myvideo();
}

public function onBWDone(... rest):Boolean {
return true;
}
public function newStream():void {
trace("newStream");
}
public function onBWCheck(... rest):Number {
return 0;
}
public function connect_chat():void {
pub_nc = new NetConnection();
var clientObj:Object = new Object();
clientObj.onBWDone = onBWDone;
clientObj.onBWCheck = onBWCheck;
pub_nc.client = clientObj;
pub_nc.connect(streamingURL);
pub_nc.addEventListener(NetStatusEvent.NET_STATUS,pub_netStatus);
pub_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecurityError);
}
public function disconnect_chat():void {
pub_nc.close();
Alert.show("映像の公開を中止しました。");
}
private function pub_netStatus(event:NetStatusEvent):void {
if (event.info.code == "NetConnection.Connect.Success") {
pub_ns = new NetStream(pub_nc);
pub_ns.attachAudio(myLocalvideo.myMic);
pub_ns.attachCamera(myLocalvideo.myCamera);
pub_ns.publish(channetKey, "live");
Alert.show("ストリーミングサーバへの接続に成功しました。");
}
else if (event.info.code == "NetConnection.Connect.Closed") {
pub_ns.close();
Alert.show("ストリーミングサーバへの接続に失敗しました。");
}
else {
trace("error");
}
}
private function onSecurityError(event:SecurityErrorEvent):void {
trace("netSecurityError:" + event);
}

}

}

AS:gueststreaming.as

package
{
import flash.media.Video;
import flash.net.NetConnection;
import flash.media.Camera;
import flash.media.Microphone;
import flash.net.NetStream;
import flash.events.*;
import mx.accessibility.AccImpl;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.events.NetStatusEvent;
import flash.events.EventDispatcher;
import mx.controls.Alert;
import mx.events.SliderEvent;
import mx.controls.sliderClasses.Slider;
import mx.rpc.events.ResultEvent;
import mx.managers.PopUpManager;
import mx.core.IFlexDisplayObject;
import mx.collections.ArrayCollection;
/**
* ...
* @author yuucha
*/
public class gueststreaming
{
private var streamingURL:String = "rtmp://192.168.116.128/buruburu";
private var play_nc:NetConnection;
private var play_ns:NetStream;
public var video:Video = new Video(320, 180);
public var channetKey:String = "";

public function gueststreaming()
{
}

public function playVideo():void{
play_nc = new NetConnection();
var clientObjplay:Object = new Object();
play_nc.client = clientObjplay;
clientObjplay.setId = function setId( id:Number ):void { };
play_nc.addEventListener(NetStatusEvent.NET_STATUS, play_netStatus);
play_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
play_nc.connect(streamingURL);
}

public function disconnect_chat():void {
play_nc.close();
}

private function onSecurityError(event:SecurityErrorEvent):void {
trace("netSecurityError:" + event);
}
private function play_netStatus(event:NetStatusEvent):void {
trace("netStatus: " + event.info.code);
if (event.info.code == "NetConnection.Connect.Success") {
Alert.show("ストリーミングサーバへの接続に成功しました。");
play_ns = new NetStream(play_nc);
video.attachNetStream(play_ns);
play_ns.play(channetKey);
} else{
trace("error");
Alert.show("ストリーミングサーバへの接続が中断しました。");
}
}
}

}

AS:myvideo.as

package
{
import flash.media.Video;
import flash.media.Camera;
import flash.media.Microphone;

/**
* ...
* @author yuucha
*/
public class myvideo
{
public var myCamera:Camera;
public var myMic:Microphone;

public function myvideo():void{
camera_init();
}

public function camera_init():void {
myCamera = Camera.getCamera();
myCamera.setMode(320,180, 30, true );
myCamera.setQuality(163840,0);
myMic = Microphone.getMicrophone();
myMic.rate = 44;
}
}

}

AS:ChatConnection.as

package
{
import flash.net.NetConnection;
import mx.controls.TextArea;

public class ChatConnection extends NetConnection
{
public var logtext:TextArea = new TextArea();

public function ChatConnection()
{
super();
logtext.width = 640;
logtext.height = 320;

}

public function writeText(message:String):void
{
logtext.text = message + "n" + logtext.text;
}

public function setlogtext(t:String):void
{
logtext.text = t;
}

public function getTextArea():TextArea
{
return logtext;
}
}
}

red5: buruburu.java

If you don’t want to use Text chat, you don’t need this code on your Red5 Webapp.

import java.util.Iterator;
import java.util.Set;

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IServiceCapableConnection;

public class Application extends ApplicationAdapter
{
// クライアント側から呼ばれるメソッド
public String drawLine(IConnection conn, int startX, int startY, int endX, int endY)
{
IScope scope = Red5.getConnectionLocal().getScope();
Set<IClient> clients = scope.getClients();
Iterator<IClient> it = clients.iterator();
Object[] params = new Object[]{startX, startY, endX, endY};
while(it.hasNext())
{
IClient client = it.next();
Set<IConnection> connset = client.getConnections();
Iterator<IConnection> it_con = connset.iterator();

while(it_con.hasNext())
{
IConnection connection = it_con.next();
if(connection instanceof IServiceCapableConnection)
{
IServiceCapableConnection sc = (IServiceCapableConnection)connection;
// クライアント側のメソッドを呼ぶ
sc.invoke("drawLine", params);
}
}
}
return "OK";

}

This version is the less text chat.

import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IServiceCapableConnection;

public class Application extends ApplicationAdapter
{
}
Leave a Comment :, more...

The sound live streaming

by admin on 1 月.21, 2009, under Showcase

This showcase is made the controller for the streaming live sound. You can change the parameters by the some slider bars.
(continue reading…)

Leave a Comment more...

The live streaming video with parameters controller.

by admin on 1 月.21, 2009, under Showcase

In this showcase, I made the controller for the streaming live Flash. You can change the parameters by the some slider bars.
If you want to know mean the parameters, Please read this page. (continue reading…)

Leave a Comment more...