10 Replies Latest reply on Sep 20, 2013 7:08 PM by LynSing717

    StageVideo usage from Flex window application(AIR dekstop)?

    LynSing717

      Hello, everyone.

      I am newbie to Flex and I'm found the flex which help me a lot.
      Recently, I found a snippet of code from forum, which does what I want but only the output is not what I expected.

      i wish to create a window application using flex project(stagevideo) which able to display video in adobe AIR. 

      the AS3 code with stagevideo class which i able to display using AS project but if i try to use the same code in flex project (not flex mobile project) i get not video output.

      I guess there is not way to attach code to this post. It's a basic window application project using flex for desktop. I appreciate if any of you able to have a look at it.
      thank you so much ^.^

      (using adobe AIR 3.8.0.870)


      (in src package>default package)

      main.mxml

      <?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"

                                                           backgroundAlpha="0">

                <fx:Declarations>

                          <!-- Place non-visual elements (e.g., services, value objects) here -->

                </fx:Declarations>

      </s:WindowedApplication>

      stageTest.as

      package

      {

                import flash.display.Sprite;

                import flash.display.Stage;

                import flash.events.Event;

                import flash.events.NetStatusEvent;

                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;

       

       

                [SWF (width="640", height="360")]

       

                public class stageTest extends Sprite

                {

                          private var stageVideoAvail:Boolean;

                          private var sv:StageVideo;

                          private var rc:Rectangle;

                          private var supportStageVideo:Boolean;

                          private var ns:NetStream;

                          private var played:Boolean;

                          private var stageVideoInUse:Boolean;

                          private var classicVideoInUse:Boolean;

                          private var vid:Video;

       

       

                          public function stageTest()

                          {

                                    stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILIT Y, onAvail);

                          }

       

                          private function onAvail(event:StageVideoAvailabilityEvent):void

                          {

                                    stageVideoAvail=(event.availability == StageVideoAvailability.AVAILABLE);

                                    initVideo();

                          }

       

                          private function initVideo():void

                          {

                                    var nc:NetConnection = new NetConnection();

                                    nc.connect(null);

                                    var ns:NetStream = new NetStream(nc);

                                    ns.client= this;

       

                                    if(stageVideoAvail)

                                    {

                                              sv:stage.stageVideos[0];

                                              sv.addEventListener(StageVideoEvent.RENDER_STATE,onRender);

                                              sv.attachNetStream(ns);

                                    }

                                    else

                                    {

                                              var vid:Video = new Video(640,360);

                                              addChild(vid);

                                              vid.attachNetStream(ns);

                                    }

                                    ns.play("try1.mp4");

                          }

       

                          private function onRender(event:StageVideoEvent):void

                          {

                                    sv.viewPort = new Rectangle(0,0,640,360);

                          }

       

                          public function onMetaData(event:Object):void

                          {

       

                          }

       

                          public function onXMPData(event:Object):void

                          {

       

                          }

       

                          private  function onStageVideoState(event:StageVideoAvailabilityEvent):void      

                          {      

                                    supportStageVideo = (event.availability  == StageVideoAvailability.AVAILABLE);  

                                    trace("supportStageVideo-="+supportStageVideo);

                                    stage.removeEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABI LITY,  onStageVideoState);

                          }

                          private function stageVideoStateChange(event:StageVideoEvent):void      

                          {         

                                    var status:String = event.status;      

                                    resize();      

                          }

       

                          private function resize ():void      

                          {         

                                    rc = computeVideoRect(sv.videoWidth, sv.videoHeight);      

                                    sv.viewPort = rc;      

                          }

                          private function computeVideoRect(s:Number,b:Number):Rectangle

                          {

                                    return new Rectangle(0,0,s,b);

                          }

                }

      }