Creating a StageVideo Test in FDT with Flex 4.5 and FlashPlayer 10.2
While trying to set up a simple Example with the StageVideo in FlashPlayer 10.2 i had lots of trouble setting up the Environment. Neither could i use Flash IDE to export correctly for FP10.2 nor could i use FDT to compile a running version.
I relied on the fact, that Flex Hero automatically includes FP10.2 which turned out to be false. Therefore i downloaded the last update and finally had the playerglobal.swc for FlashPlayer 10.2 available.
After having this working, the Example to check the performance was a piece of cake.
package vid { import flash.display.Sprite; import flash.display.Stage; import flash.events.StageVideoAvailabilityEvent; import flash.events.StageVideoEvent; import flash.geom.Rectangle; import flash.media.StageVideo; import flash.media.StageVideoAvailability; import flash.media.Video; import flash.net.NetConnection; import flash.net.NetStream; /** * @author patricktresp */ public class StageVideoTest extends Sprite { private var _nc : NetConnection; private var _ns : NetStream; private var _stageVideo : StageVideo; private var _video : Video; public function StageVideoTest() { var stage : Stage = Main.getInstance().stage; stage.addEventListener( StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onStageVideoState ); } private function onStageVideoState( event : StageVideoAvailabilityEvent ) : void { var available : Boolean = (event.availability == StageVideoAvailability.AVAILABLE); _nc = new NetConnection(); _nc.connect( null ); _ns = new NetStream( _nc ); _ns.bufferTime = 0; var customClient : Object; customClient = new Object; customClient.onMetaData = onMetaDataHandler; _ns.client = customClient; if ( available ) { addStageVideo(); } else { addRegularVideo(); } _ns.play( "video/hd.f4v" ); } private function addRegularVideo() : void { var stage : Stage = Main.getInstance().stage; var video : Video = _video = new Video(); video.smoothing = true; video.attachNetStream( _ns ); stage.addChildAt( video, 0 ); } private function addStageVideo() : void { var stage : Stage = Main.getInstance().stage; var v : Vector. = stage.stageVideos; var sv : StageVideo; if ( v.length >= 1 ) { sv = _stageVideo = v[0]; sv.addEventListener( StageVideoEvent.RENDER_STATE, stageVideoStateChange ); sv.attachNetStream( _ns ); } } private function stageVideoStateChange( event : StageVideoEvent ) : void { resize(); } private function resize() : void { _stageVideo.viewPort = new Rectangle( 0, 0, _stageVideo.videoWidth, _stageVideo.videoHeight ); } private function onMetaDataHandler( meta : Object ) : void { if ( _video ) { _video.width = meta.width; _video.height = meta.height; } } } }
Next Step will be the test within an existing application running in Projector.
For Performance Testing i used a very fast Picture-Changing Movie:
No StageVideo:
Yes StageVideo:
Of Course the video.smoothing has a direct effect on the high CPU-usage, without smoothing:
Still more than 30% saved and another step closer to “green programming”.
