actionscript 3 - How can I fix this video phone app? -
i'm trying practice making simple video phone app i'm trying make program send video , recieve video using cirrus adobe. i'm having trouble recieving stream though. here cod 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 getting 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 sendstream = new netstream(netconnection, netstream.direct_connections); sendstream.addeventlistener(netstatusevent.net_status,netstreamhandler); //setup camera var cam:camera = camera.getcamera(); //attach camera to sendstream sendstream.attachcamera(cam); //publish sendstream sendstream.publish("media"); //attach camera 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 recvstream recvstream.play("media"); writetext("recvstream.play(media)"); //attach stream myvid myvid.mx_internal::videoplayer.attachnetstream(recvstream); } else { theirid.text = "please place id here."; } } private function netstreamhandler(event:netstatusevent):void{ writetext(event.info.code); switch(event.info.code){ case "netconnection.connect.success": //display 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 getvideoreveiver()
function i'm getting flag go off writetext("flag")
, output in text box of:
netstream.play.reset netstream.play.start
from netstreamhandler
, video never shows in receiving video element.
i'm running 2 different videos of same computer , taking nearid 1 stream , pasting textinput theirid
. i'm not sure try next?
here script got working example. need 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 needed 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 getting 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 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 sendstream = new netstream(netconnection, netstream.direct_connections); sendstream.addeventlistener(netstatusevent.net_status,netstreamhandler); //setup camera var cam:camera = camera.getcamera(); //attach camera to sendstream sendstream.attachcamera(cam); //publish sendstream sendstream.publish("media"); //attach camera 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 recvstream recvstream.play("media"); writetext("recvstream.play(media)"); //attach stream videorecv videorecv.attachnetstream(recvstream); } else { theirid.text = "please place id here."; } } private function netstreamhandler(event:netstatusevent):void{ writetext(event.info.code); switch(event.info.code){ case "netconnection.connect.success": //display 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()"/>
Comments
Post a Comment