Adobe record sound and save - actionscript-3

In the following code i am trying to save the microphone contents to a file.The saved file doesn't play and Every time the file is saved i see that the size is only of 10 bytes only.What am i doing wrong in the code.Can someone please show me the correct code to save it .And the saved file should play the recorded contents accordingly.
<?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" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.net.FileReference;
import mx.controls.Alert;
import flash.net.FileReference;
import flash.display.Sprite;
import flash.media.Sound;
import flash.utils.ByteArray;
import flash.external.ExternalInterface;
public var _file:FileReference = new FileReference();
[Bindable] private var micList:Array;
public var mic:Microphone = Microphone.getMicrophone();
protected var isRecording:Boolean = false;
protected function startMicRecording():void
{
//var mic:Microphone = Microphone.getMicrophone();
mic.gain = 60;
mic.rate = 11;
mic.setUseEchoSuppression(true);
mic.setLoopBack(true);
mic.setSilenceLevel(5, 1000);
Alert.show("In recording");
isRecording = true;
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
protected function stopMicRecording():void
{
//isRecording = false;
try{
//_file.save( SampleDataEvent.SAMPLE_DATA, "recorded.wav" );
_file.save(SampleDataEvent.SAMPLE_DATA , "recorded.flv" );
}
catch(e:Error)
{
Alert.show("In Stopmicrecording"+e);
}
}
private function gotMicData(micData:SampleDataEvent):void
{
//mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
protected var soundRecording:ByteArray;
protected var soundOutput:Sound;
protected function playbackData():void
{
}
private function playSound(soundOutput:SampleDataEvent):void
{
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ComboBox x="150" id="comboMicList" dataProvider="{micList}" />
<mx:Button x="250" id="startmicrec" label="Start Rec" click="startMicRecording()"/>
<mx:Button x="350" id="stopmicrec" label="Stop Rec" click="stopMicRecording()"/>
<!--<mx:Button x="50" id="setupmic" label="Select Mic" click="setupMicrophone()"/>-->
<mx:Button x="450" id="playrecsound" label="Play sound" click="playbackData()"/>
</s:Application>

You need to store the data that is handed to you in gotMicData into a ByteArray and then save that ByteArray. You are saving the event name, which is a string (10 characters long).
Once you do that, you need to load the file and hand sample data to the sound. You play the sound back 8 times... because you sampled at 11 KHz but the sound plays back at 44 KHz (4x writing) and the sound is Stereo but the mic is mono (2x again).
You can't save the data as a WAV file directly... you recorded raw data. If you want to go through the trouble of writing a proper WAV header, then you don't have to play the games of handing sample data and hand the file to the Sound object. That is an exercise outside of the scope of this question.
Good luck!
import mx.controls.Alert;
public var mic:Microphone = Microphone.getMicrophone();
public var recordedData:ByteArray;
protected function startMicRecording():void
{
mic.gain = 60;
mic.rate = 11;
mic.setUseEchoSuppression(true);
mic.setLoopBack(false);
mic.setSilenceLevel(5, 1000);
recordedData = new ByteArray();
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}
protected function stopMicRecording():void
{
mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
try{
var file:FileReference = new FileReference();
file.save(recordedData, "recorded.dat" );
}
catch(e:Error)
{
Alert.show("In Stopmicrecording"+e);
}
}
private function gotMicData(sample:SampleDataEvent):void
{
recordedData.writeBytes(sample.data, 0, sample.data.bytesAvailable);
}
protected var playbackFile:FileReference;
protected var soundRecording:ByteArray;
protected var soundOutput:Sound;
protected function playbackData():void
{
playbackFile = new FileReference();
playbackFile.addEventListener(Event.SELECT, playbackFileSelected);
playbackFile.browse();
}
private function playbackFileSelected(event:Event):void {
playbackFile.addEventListener(Event.COMPLETE, playbackFileLoaded);
playbackFile.load();
}
private function playbackFileLoaded(event:Event):void {
soundRecording = playbackFile.data;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, moreInput);
soundOutput.play();
}
private function moreInput(event:SampleDataEvent):void {
var sample:Number;
for (var i:int = 0; i < 1024; i++) {
if (soundRecording.bytesAvailable > 0) {
sample = soundRecording.readFloat();
// write the same byte 8 times:
// Upsample from 11 KHz to 44 KHz (x4)
// Mono to Stereo (x2)
for(var x:int = 0; x < 8; x++)
event.data.writeFloat(sample);
}
}
}

Related

Playing a video with flex, AS3

I am currently trying to make a game on flex and one of the problems I ran in to is how to play a short animation at the beginning. This is what I have so far:
Game.mxml
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
name="Game"
backgroundColor="#000000"
horizontalAlign="center"
creationComplete="Init();"
enterFrame="UpdateFrame();"
paddingLeft="0"
paddingTop="0"
paddingBottom="0"
paddingRight="0"
width="800" height="600">
<mx:Script>
<![CDATA[
include "Game.as";
]]>
</mx:Script>
<mx:Canvas id="gamePanel" x="0" y="0" width="100%" height="100%" mouseDown="MouseDown(event)" mouseUp="MouseUp(event)" mouseMove="MouseMoved(event)"/>
</mx:Application>
and Game.as
import flash.display.*;
import flash.events.*;
import flash.external.ExternalInterface;
import mx.events.*;
import mx.controls.*;
[Embed(source="MyVideoClip.flv")] private var MyVideoClip:Class;
public function Init():void
{
var MyVideo:Video = new Video(800, 600);
addChild(MyVideo);
var qNetConnection:NetConnection = new NetConnection();
qNetConnection.connect(null);
var qNetStream:NetStream = new NetStream(qNetConnection);
MyVideo.attachNetStream(qNetStream);
qNetStream.client = new Object();
qNetStream.play(MyVideoClip);
}
private function UpdateFrame():void
{
}
private function MouseDown(event:MouseEvent):void
{
}
private function MouseUp(event:MouseEvent):void
{
}
private function MouseMoved(event:MouseEvent):void
{
}
I am rather new to Flex and AS3 so most of this code was ripped off web tutorials. Whenever I try to compile it I get: 'Error: 'MyVideoClip.flv' does no have a recongnized extention, and a mimeType was not provided. Error: unable to transcode 'MyVideoClip.flv''
If I remove the 'embed' line and replace MyVideoClip with "MyVideoClip.flv" in the play() function, the code compiles with no errors, but when I open the SWF all I get is a black screen. What am I doing terribly wrong?
Thanks in advance!!
Try setting the mime-type, e.g.:
[Embed(source = "MyVideoClip.flv", mimeType = "application/octet-stream")]
You embedded the video file (its bytes) into the output SWF. So now NetStream must play from a bytes source. Just set a byteArray as equal to new MyVideoClip(); and append to NetStream.
Try this...
[Embed(source="MyVideoClip.flv", mimeType="application/octet-stream")] private var MyVideoClip:Class; //# embed the FLV's bytes
public var VideoClipBytes : ByteArray;
public var MyVideo:Video;
public var qNetConnection:NetConnection;
public var qNetStream:NetStream;
public function Init():void
{
VideoClipBytes = new MyVideoClip() as ByteArray; //# fill a byte Array with embedded bytes
qNetConnection = new NetConnection(); qNetConnection.connect(null);
qNetStream = new NetStream(qNetConnection);
qNetStream.client = new Object();
MyVideo = new Video(800, 600);
MyVideo.attachNetStream(qNetStream);
addChild(MyVideo);
qNetStream.play(null); //# play mode is now bytes
qNetStream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN); //# ready for new audio/video data
qNetStream.appendBytes( VideoClipBytes ); //# add bytes to decoder queue (playback)
}
PS : I made some of your variables as public so later you can access & control them from any other functions. Remember if you make var inside a public function it stays valid only in that one function and doesn't exist to other functions. Best make such vars as publicly available to all functions.

AIR app:How to load swf from server

My app structure is below:
(local)
Login.swf
(server)
Main.swf
assets1.swf
assets2.swf
Login.swf -> Main.swf (OK!)
Main.swf -> assets1&2.swf (fail!, downloaded but not trigger complete event)
-progress event: bytes:loaded==total
Why?
How can i load assets from server using Main.swf?
I found somebody say it is crossdomain problem...then how to solve?
var _loader:Loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.allowCodeImport = true;
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete_handler);
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loader_progress_handler);
_loader.loadBytes(_urlloader.data,context);
Thanks!
BE AWARE:
On mobile it only works on Android... iOS due to a security policy does not permit to load an swf inside another one.
Said that you can surerly load an SWF.
First of all we need to understand if you can download the SWF bytearray using the URLLoader.
if yes you can load the swf in a two step routine..
hope this help :)
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
showStatusBar="false"
creationComplete="downloadSwf()">
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.SystemManager;
import spark.components.Application;
private function downloadSwf():void {
// load the file with URLLoader into a bytearray
sfwLoader.visible = false;
var loader:URLLoader = new URLLoader();
// binary format since it a SWF
loader.dataFormat=URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, onSWFLoaded);
loader.addEventListener(IOErrorEvent.IO_ERROR, cantConnect);
//load the file
loader.load(new URLRequest("url"));
}
private function cantConnect(e:IOErrorEvent):void
{
var loader:URLLoader=URLLoader(e.target);
loader.removeEventListener(Event.COMPLETE, onSWFLoaded);
loader.removeEventListener(IOErrorEvent.IO_ERROR, cantConnect);
// error handling
return;
}
private function onSWFLoaded(e:Event):void {
// remove the event
var loader:URLLoader=URLLoader(e.target);
loader.removeEventListener(Event.COMPLETE, onSWFLoaded);
loader.removeEventListener(IOErrorEvent.IO_ERROR, cantConnect);
// add an Application context and allow bytecode execution
var context:LoaderContext=new LoaderContext();
context.allowLoadBytesCodeExecution=true;
// set the new context on SWFLoader
sfwLoader.loaderContext = context;
sfwLoader.addEventListener(Event.COMPLETE, loadComplete);
// load the data from the bytearray
sfwLoader.load(loader.data);
}
// your load complete function
private function loadComplete(completeEvent:Event):void {
sfwLoader.removeEventListener(Event.COMPLETE, loadComplete);
var swfApplication:* = completeEvent.target.content;
var sysmgr:SystemManager = (swfApplication as SystemManager);
sysmgr.addEventListener(FlexEvent.APPLICATION_COMPLETE, swfAppComplete);
}
private function swfAppComplete(event:FlexEvent):void {
sfwLoader.visible = true;
var sysmgr:SystemManager = (event.currentTarget as SystemManager);
sysmgr.removeEventListener(FlexEvent.APPLICATION_COMPLETE, swfAppComplete);
var swfApp:Application = (sysmgr.application as Application);
if (!swfApp.hasOwnProperty("version")) {
return;
}
// version is a public property in the main of the loaded application
var verion:String = swfApp["version"];
swfApp.addEventListener(Event.CLOSE, appClose);
}
private function appClose(e:Event):void
{
sfwLoader.unloadAndStop(true);
NativeApplication.nativeApplication.exit();
}
private function closeApp(e:CloseEvent):void
{
try{
(FlexGlobals.topLevelApplication as WindowedApplication).close();
}
catch(e:Error){}
}
]]>
</fx:Script>
<mx:SWFLoader id="sfwLoader"
width="100%" visible="false"
height="100%"/>
</s:WindowedApplication>

How to play an m4a sound file

The code below imports and controls an mp3 sound file. When I change from an mp3 to an m4a file the code does not work. Do I need to use a different class to play an m4a file?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="init()" >
<mx:Script>
<![CDATA[
import mx.events.ItemClickEvent;
import mx.rpc.events.ResultEvent;
private var sound:Sound;
private var soundChannel:SoundChannel = new SoundChannel;
private var loaderContext:SoundLoaderContext;
private var trackPosition:Number = 0;
private var timer:Timer;
private var leftGraphic:Sprite;
private var rightGraphic:Sprite;
private function init():void{
var audioFile:String = "recording.mp3";
sound = new Sound(new URLRequest(audioFile));
sound.addEventListener(Event.COMPLETE, onSoundLoaded);
function onSoundLoaded(event:Event):void{
maxTime.text = convertMillesecs(sound.length)
trackSlider.y-= 5;
trackSlider.maximum = sound.length;
}
}
private var counter:Number
private function soundComplete( e:Event ):void{
maxTime.text = convertMillesecs(soundChannel.position);
maxTime.text = convertMillesecs(sound.length)
}
private function checkTrack(event:Event):void{
// manage track counter
trackSlider.value = soundChannel.position;
currentVal.text = String(convertMillesecs(soundChannel.position));
}
private function convertMillesecs(time:Number):String{
var h:Number = new Number(Math.floor(time/1000/60/60));
var m:Number = new Number(Math.floor(time/1000/60)-(h*60));
var s:Number = new Number(Math.floor(time/1000)-(m*60));
var hours:String;
var minutes:String;
var seconds:String
//minutes and seconds always two digits
if(m.toString().length == 1) {
minutes = "0"+m;
} else {
minutes = m.toString();
}
if(s.toString().length == 1) {
seconds = "0"+s;
} else {
seconds = s.toString();
}
// last two digits represent actual seconds
seconds = seconds.slice(seconds.length-2, seconds.length);
return minutes + ":" + seconds;
}
private function controlChange1(event:MouseEvent):void{
var optionString:String;
switch(event.target.id){
case "playButton":
play();
break;
case "pauseButton":
pause();
break;
default:
break;
}
}
private function play():void{
playButton.visible = false;
pauseButton.visible = true;
timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, checkTrack);
soundChannel.stop();
soundChannel = sound.play(pausePosition);
timer.start();
}
private var pausePosition:int
private function pause():void{
pausePosition = soundChannel.position;
soundChannel.stop();
playButton.visible = true;
pauseButton.visible = false;
}
private function onTrackSliderChange(e:Event):void{
soundChannel.stop()
soundChannel = sound.play(e.target.value * sound.length / trackSlider.maximum);
playButton.visible = false;
pauseButton.visible = true;
}
private function formatButton(val:String):String{
return convertMillesecs(soundChannel.position)
}
]]>
</mx:Script>
<mx:HBox backgroundColor="0x000000" horizontalCenter="0" verticalCenter="0" verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
<mx:Canvas id="controlBar1" paddingLeft="1" buttonMode="true" useHandCursor="true" >
<mx:Button id="pauseButton" width="40" height="40" click="controlChange1(event)" visible="false" color="0x0B333C"/>
<mx:Button id="playButton" width="40" height="40" click="controlChange1(event)" color="0x000000" />
</mx:Canvas>
<mx:Label id="currentVal" text="00:00" color="0xffffff"/>
<mx:HSlider id="trackSlider" height="10" width="500" liveDragging="false" change="onTrackSliderChange(event);"
dataTipFormatFunction="formatButton" showTrackHighlight = "true" mouseEnabled="true" useHandCursor="true" />
<mx:Label id="maxTime" text="00:00" color="0xffffff"/>
</mx:HBox>
</mx:Application>
The Sound class can play one of two formats: mp3 and the raw format AS3 records to. So it is impossible to use the Sound class to play m4a, unfortunately.
Fortunately, it is possible to play m4a using another class: NetStream. You may or may not have as fine of control over it without the SoundTransform and SoundMixer classes, but you can still play the file no problem (I've done it in the past, though it didn't end up working quite the way I was hoping for so I ended up going with mp3s instead)
Adobe Article on m4a playback

Drag and Drop Image loaded by flex-loader. Original Source should not be removed

yesterday me and my friend Ketan thakkar were working on an issue related with drag drop in flex.
Image can dragged easily if it is has direct your or embedded image.
But if we try to drag image which has a source from flex loader, original image loos the parent and then never go back to its original place. We tried to find the solution and with a good luck we got success.
the code is below. If anyone know why this problem exist please help us.
For now we have managed it this way.
<?xml version="1.0" encoding="utf-8"?>
<mx:Script>
<![CDATA[
import mx.controls.Image;
import mx.core.DragSource;
import mx.core.FlexLoader;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.events.FlexEvent;
import mx.graphics.ImageSnapshot;
import mx.managers.DragManager;
private var fl:FlexLoader = new FlexLoader();
private var img1:Image = new Image();
private function doDragEnter(event:DragEvent):void
{
DragManager.acceptDragDrop(UIComponent(event.target));
}
private function doDragDrop(event:DragEvent):void
{
var img:Image;
if (event.dragInitiator.parent == dropCanvas)
img = event.dragInitiator as Image;
else
{
img = new Image();
img.width = img.height = 120;
img.source = img1.source;
img.addEventListener(MouseEvent.MOUSE_DOWN, doDragStart);
dropCanvas.addChild(img);
}
img.x = event.localX - (event.dragSource.dataForFormat("localX") as Number);
img.y = event.localY - (event.dragSource.dataForFormat("localY") as Number);
}
private function doDragStart(event:MouseEvent):void
{
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(event.currentTarget as IBitmapDrawable);
var imageByteArray:ByteArray = imageSnap.data as ByteArray;
img1.load(imageByteArray);
var dragInitiator:Image = event.currentTarget as Image;
var dragSource:DragSource = new DragSource();
var dragProxy:Image = new Image();
dragProxy.source = img1.source;
dragProxy.x = mouseX-25;
dragProxy.y = mouseY-25;
dragProxy.width = 80;
dragProxy.height= 80;
DragManager.doDrag(dragInitiator, dragSource, event, dragProxy,0,0,1,false);
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
fl.contentLoaderInfo.addEventListener(Event.COMPLETE, oncomplete);
fl.load( new URLRequest('assets/1.swf'));
}
private function oncomplete(event:Event):void
{
img.source = fl;
}
]]>
</mx:Script>
<controls:FlexBook width="400" height="200"
itemSize="halfPage">
<controls:content>
<mx:Image id="img" mouseDown="doDragStart(event)" /><!--source="#Embed('assets/Hawk.jpg')"-->
<mx:Image id="img11" mouseDown="doDragStart(event)" /><!--source="#Embed('assets/Hawk.jpg')"-->
<mx:Image id="img2" mouseDown="doDragStart(event)" /><!--source="#Embed('assets/Hawk.jpg')"-->
</controls:content>
</controls:FlexBook>
<mx:Canvas id="dropCanvas" width="100%" height="100%" borderColor="#1C5CC7" dragEnter="doDragEnter(event)" dragDrop="doDragDrop(event)" borderStyle="solid" cornerRadius="20" borderThickness="6" backgroundColor="#7E92FC"/>
<!--<mx:Image id="dropImage" source="assets/1.swf" />-->
I had a similar problem, the problem is in this line:
dragProxy.source = img1.source;
you should to copy bitmap img1 like here instead linking it.

How can I fix this video phone app?

I'm trying to practice making a simple video phone app so I'm trying to make a program to send a video and recieve a video using Cirrus from Adobe. I'm having trouble recieving the stream though. Here is the cod that I'm using:
<?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" applicationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.core.mx_internal;
import spark.components.Group;
private const SERVER:String = "rtmfp://p2p.rtmfp.net/";
private const DEVKEY:String = "MY-DEV-KEY";
[Bindable]
//Net Connection variable
private var netConnection:NetConnection;
//Sending video stream var
private var sendStream:NetStream;
//Sending video video var
private var videoSend:Video;
//Receiving video stream var
private var recvStream:NetStream;
//String for getting their ID
private var id_of_publishing_client:String;
private function init():void {
//Setup videoSend
videoSend = new Video(320,240);
videoSend.x = 10;
videoSend.y = 10;
var uic:UIComponent = new UIComponent();
uic.addChild(videoSend);
addElement(uic);
//connect
connect();
}
private function connect():void{
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
netConnection.connect(SERVER,DEVKEY);
}
private function setupStreamOutgoing():void{
//Send Stream setting up
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);
//setup camera
var cam:Camera = Camera.getCamera();
//attach the camera to the to the sendStream
sendStream.attachCamera(cam);
//publish the sendStream
sendStream.publish("media");
//attach the camera to the videoStream object
videoSend.attachCamera(cam);
}
private function getVideoReceiver():void{
id_of_publishing_client = theirID.text;
writeText("inside getVideoReceiver()");
if(id_of_publishing_client){
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
writeText("flag");
//play the recvStream
recvStream.play("media");
writeText("recvStream.play(media)");
//attach the stream to the myVid
myVid.mx_internal::videoPlayer.attachNetStream(recvStream);
}
else {
theirID.text = "Please place an ID here.";
}
}
private function netStreamHandler(event:NetStatusEvent):void{
writeText(event.info.code);
switch(event.info.code){
case "NetConnection.Connect.Success":
//Display my ID in myID.text
myID.text = netConnection.nearID;
setupStreamOutgoing();
break;
case "NetStream.Connect.Success":
break;
case "NetStream.Connect.Closed":
break;
}
}
private function writeText(txt:String):void{
txtHistory.text += txt+"\n";
}
]]>
</fx:Script>
<s:TextArea top="10" bottom="10" id="txtHistory" width="252" right="10"/>
<s:TextInput id="theirID" x="112" y="342" width="437"/>
<s:TextInput id="myID" x="112" y="312" width="437"/>
<s:Button x="10" y="312" label="My Connection" width="94" />
<s:Button x="10" y="341" label="Their Connection" width="94" click="getVideoReceiver()"/>
<mx:VideoDisplay id="myVid"
x="340"
y="10"
width="320" height="240" />
</s:Application>
Inside of the getVideoReveiver() function I'm getting the flag to go off from writeText("flag") then I get and output in the text box of:
NetStream.Play.Reset
NetStream.Play.Start
from the netStreamHandler, but the video never shows up in the receiving video element.
I'm running this is two different videos of the same computer and taking the nearID from one stream and pasting it into the textInput theirID. I'm not sure what to try next?
Here is the script that I got working for anyone who would like this as an example. All you need is a Cirrus dev key.
<fx:Script>
<![CDATA[
import mx.core.UIComponent;
import mx.core.mx_internal;
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import spark.components.Group;
private const SERVER:String = "rtmfp://p2p.rtmfp.net/";
private const DEVKEY:String = "YOUR-DEV-KEY";
[Bindable]
//Net Connection variable that is needed to s
private var netConnection:NetConnection;
//Sending video stream var
private var sendStream:NetStream;
//Sending video video var
private var videoSend:Video;
//receiving video video var
private var videoRecv:Video;
//Receiving video stream var
private var recvStream:NetStream;
//String for getting their ID
private var id_of_publishing_client:String;
private function init():void {
//Setup videoSend
videoSend = new Video(320,240);
videoSend.x = 10;
videoSend.y = 10;
//Setup videoRecv
videoRecv = new Video(320,240);
videoRecv.x = 340;
videoRecv.y = 10;
var uic:UIComponent = new UIComponent();
uic.addChild(videoSend);
uic.addChild(videoRecv);
addElement(uic);
//connect to cirrus
connect();
}
private function connect():void{
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
netConnection.connect(SERVER,DEVKEY);
}
private function setupStreamOutgoing():void{
//Send Stream setting up
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);
//setup camera
var cam:Camera = Camera.getCamera();
//attach the camera to the to the sendStream
sendStream.attachCamera(cam);
//publish the sendStream
sendStream.publish("media");
//attach the camera to the videoStream object
videoSend.attachCamera(cam);
}
private function getVideoReceiver():void{
id_of_publishing_client = theirID.text;
writeText("inside getVideoReceiver()");
if(id_of_publishing_client){
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
writeText("flag");
//play the recvStream
recvStream.play("media");
writeText("recvStream.play(media)");
//attach the stream videoRecv
videoRecv.attachNetStream(recvStream);
}
else {
theirID.text = "Please place an ID here.";
}
}
private function netStreamHandler(event:NetStatusEvent):void{
writeText(event.info.code);
switch(event.info.code){
case "NetConnection.Connect.Success":
//Display my ID in myID.text
myID.text = netConnection.nearID;
setupStreamOutgoing();
break;
case "NetStream.Connect.Success":
break;
case "NetStream.Connect.Closed":
break;
case "NetStream.Play.Start":
break;
}
}
private function writeText(txt:String):void{
txtHistory.text += txt+"\n";
}
]]>
</fx:Script>
<s:TextArea top="10" bottom="10" id="txtHistory" width="252" right="10"/>
<s:TextInput id="theirID" x="112" y="342" width="437"/>
<s:TextInput id="myID" x="112" y="312" width="437"/>
<s:Button x="10" y="312" label="My Connection" width="94" />
<s:Button x="10" y="341" label="Their Connection" width="94" click="getVideoReceiver()"/>