Skip navigation
Currently Being Moderated

StageVideo usage from Flex window application(AIR dekstop)?

Sep 5, 2013 8:03 PM

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.STA GE_VIDEO_AVAILABILITY, 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_AVAILABILITY,  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);

                    }

          }

}

 
Replies
  • Currently Being Moderated
    Sep 6, 2013 8:56 AM   in reply to LynSing717

    Search the internet for how other folks have done it.  I think they set backgroundAlpha=0 on the Application tag.  Do you hear the audio?  I think Flex defaults to drawing a background that covers the video.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 8, 2013 9:01 PM   in reply to LynSing717

    So you see the video but there is no audio?  Maybe try another video.

     

    -Alex

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 8, 2013 9:40 PM   in reply to LynSing717

    See this thread: http://forums.adobe.com/message/4554510

    Also check the documentation about using renderMode or wmode correctly.

     

    -Alex

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2013 8:29 AM   in reply to LynSing717

    You may find that a custom skinClass works, especially if a backgroundImage is being used.  But you should be hearing audio and just not seeing video if that is the problem.

     

    If you don't even get audio, you may want to try an ActionScript-only Project that uses StageVideo and/or a regular Flex project that uses the Spark or mx Video controls to make sure Flash can find and display the video.  There might be a security issue or a bad URL preventing the video from playing anything at all.

     

    There are some differences between mobile and non-mobile AIR application support, but I don't know if video is one of the differences.

     

    -Alex

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 12, 2013 9:32 PM   in reply to LynSing717

    I've never really worked with video.  Try an ActionScript-only project.  Make sure the renderMode/wmode is set correctly.  Here's one article: http://www.adobe.com/devnet/flashplayer/articles/stage_video.html

     

    -Alex

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points