Created
July 27, 2010 21:07
-
-
Save shamun/492861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" | |
layout="absolute" | |
xmlns:cam="*" | |
viewSourceURL="srcview/index.html"> | |
<!-- | |
NOTE: | |
FlexBuilder now displays the live feed from your webcam when you switch to | |
Design view. Which is sort of cool and all but when you switch back to | |
Source view it doesn't let go of the camera. So when you publish/test the | |
application you won't be able to see anything - or record - because FlexBuilder | |
already has the stream and there can be only one. | |
You'll have to restart FlexBuilder to get it to give up the connection to your webcam. | |
--> | |
<cam:webcam id="recorder" x="10" y="10" /> | |
<mx:Button id="recordToggle" click="onRecord( event );" label="Start Recording" x="106" y="278"/> | |
<mx:Script> | |
<![CDATA[ | |
private function onRecord( e:Event ):void { | |
if( recordToggle.label == "Start Recording" ) { | |
recorder.recordStream( true ); | |
recordToggle.label = "Stop Recording"; | |
} else { | |
recorder.recordStream( false ); | |
recordToggle.label = "Start Recording"; | |
} | |
} | |
]]> | |
</mx:Script> | |
</mx:Application> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<mx:Canvas creationComplete="init();" xmlns:mx="http://www.adobe.com/2006/mxml" width="320" height="240"> | |
<mx:Metadata> | |
[Event(name="recordStreamStart", type="events.CustomEventClass")] | |
[Event(name="recordStreamStop", type="events.CustomEventClass")] | |
</mx:Metadata> | |
<mx:Script> | |
<![CDATA[ | |
//import flash.media.Camera; | |
private var nc:NetConnection = new NetConnection(); | |
private var publish_ns:NetStream; | |
//private var cam:Camera; | |
private var mic:Microphone; | |
private function init():void { | |
// this is what you'll change to point to different servers/applications | |
nc.connect( "rtmp://localhost/live/" ); | |
// get a reference to the audio stream that gets attached to the Netstream | |
mic = Microphone.getMicrophone(); | |
// you can't add a NetConnection to a NetStream until the NetConnection is | |
// actually connected. So we wait for a status event. | |
nc.addEventListener( NetStatusEvent.NET_STATUS, onStatus ); | |
} | |
public function onStatus( e:Event ):void { | |
// now we can set the publish_ns connection to our 'nc' | |
publish_ns = new NetStream( nc ); | |
// get the web cam video stream | |
//cam = Camera.getCamera(); | |
// here at polyGeek we are all about the best possible quality! | |
//cam.setQuality( 0, 100 ); | |
// attach the cam stream to our NetStream | |
//publish_ns.attachCamera( cam ); | |
// attach the audio | |
publish_ns.attachAudio( mic ); | |
// attach the cam stream to the VideoDisplay - id="webCam" - below | |
// so that we can see our web cam stream | |
//webCam.attachCamera( cam ); | |
} | |
public function recordStream( isRecording:Boolean ):void { | |
if( isRecording ) { | |
recordStreamStart(); | |
} else { | |
recordStreamStop(); | |
} | |
} | |
private function recordStreamStart():void { | |
// get a unique filename for the stream to be saved | |
var fileName:String = "Flex_" + String( Math.random() ); | |
publish_ns.publish( fileName, "record" ); | |
} | |
private function recordStreamStop():void { | |
publish_ns.close(); | |
} | |
]]> | |
</mx:Script> | |
<mx:VideoDisplay id="webCam" width="320" height="240" /> | |
</mx:Canvas> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment