6 Replies Latest reply on May 10, 2010 8:00 AM by toft

    Getting rid of a video

    toft

      I have an app that loads and unloads comps into a vgroup. In one of these comps I have a VideoDisplay. When loading another comp I naturally need my video comp to shut up and go away. I have tried stopping the video from anywhere I can think of, inside and outside the comp itself. No luck at all, it happily plays on. (On each new comp loading the vgroup is emptied before loading a new one)

       

      I have no problem accessing the video comp from the main app. But calling stop() on it does nothing.

       

      NB! In this case its not an alternative to have a button so the video can be stopped manually. I want it to automaticly stop when loading new stuff.

       

      What to do ??

        • 1. Re: Getting rid of a video
          David_F57 Level 5

          hi

           

          If you load the comp and it has a videoplayer in it then you should have no issues sending commands to it from the main app.

           

           

          David

           

          myApp

          ======

           

          <?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" minWidth="955" minHeight="600" xmlns:ns1="*">

          <fx:Script>

          <![CDATA[

           

          protected function button1_clickHandler(event:MouseEvent):void

          {

          myvp.vp.stop();

          myvp.vp.source=null;

          }

           

           

          protected function button2_clickHandler(event:MouseEvent):void

          {

          myvp.vp.source="03.flv";

          myvp.vp.play();

          }

           

          ]]>

          </fx:Script>

           

          <ns1:myVideoPlayer id="myvp" x="711" y="212"/>

          <s:Button x="913" y="128" label="Unload" click="button1_clickHandler(event)"/>

          <s:Button x="787" y="128" label="Load" click="button2_clickHandler(event)"/>

          </s:Application>

           

          myComponent

          ===========

          <?xml version="1.0" encoding="utf-8"?>

          <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"

          xmlns:s="library://ns.adobe.com/flex/spark"

          xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

          <fx:Declarations>

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

          </fx:Declarations>

          <s:VideoPlayer id="vp" x="26" y="19" width="344" height="255"/>

          </s:Group>

           

          • 2. Re: Getting rid of a video
            toft Level 1

            Thanks David

             

            I have no problem accessing (tracing shows it) the component containing the video display from the main app. It simply doesnt respond to stop();, source = null;

             

            Note: In your sample you include the component in mxml. I add the components dynamicly using as. Can that make difference when loading / unloading components ?

            • 3. Re: Getting rid of a video
              David_F57 Level 5

              hi,

               

              I tried it loading an as component dynamically and still it worked, can you give me an idea of how you are instantiating the component...

               

              application

              ========

              <?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" minWidth="955" minHeight="600" xmlns:ns1="*" creationComplete="application1_creationCompleteHandler(event)">

               

              <fx:Script>

              <![CDATA[

              import mx.events.FlexEvent;

               

              private var mp:myPlayer;

               

              protected function button1_clickHandler(event:MouseEvent):void

              {

              mp.vp.source="03.flv";

              mp.vp.play();

              }

               

              protected function button2_clickHandler(event:MouseEvent):void

              {

                 mp.vp.stop();

                 mp.vp.source=null;

              }

               

              protected function application1_creationCompleteHandler(event:FlexEvent):void

              {

              mp = new myPlayer();

              mp.width=600;

              mp.height=400;

              mp.x=5;

              mp.y=40;

              this.addElement(mp);

               

              }

               

              ]]>

              </fx:Script>

               

              <s:Button x="5" y="5" label="load" click="button1_clickHandler(event)"/>

              <s:Button x="75" y="5" label="unload" click="button2_clickHandler(event)"/>

              </s:Application>

              component

              ========

              package

              {

              import spark.components.Group;

              import spark.components.VideoPlayer;

               

              public class myPlayer extends Group

              {

              public var vp:VideoPlayer = new VideoPlayer();

               

              public function myPlayer()

              {

              super();

              width=400;

              height=300;

              vp.width = this.width;

              vp.height = this.height;

              addElement(vp);

              }

              }

              }

              • 4. Re: Getting rid of a video
                toft Level 1

                Hi David, thanks again...

                 

                Switch in main app:

                 

                case 'ReflectionVideo':
                                        reflectionVideo =  new ReflectionVideo();
                                        initPage(new ReflectionVideoInfo(), new ReflectionVideo(), 20);
                                        break;

                 

                Loading it works fine. And for testing I added a stop-button (as in your last sample) and it stopped the video. The problem is that I dont want a button to stop it, I want it to stop when unloading the videocontainer and  loading new content into the 'host' in the main app. Loading and unloading the various other content works just fine, I just cant that &£# video to shut up !!

                 

                As I`ve mentioned earlier, accessing the reflectionVideo component and it`s video from the main app works fine when trace testing. It just refuse to respond to a stop call.

                • 5. Re: Getting rid of a video
                  David_F57 Level 5

                  hi,

                   

                  The only thing I can think of is that you have 2 instances of the component running but one is not visible, i tried something interesting, I modified my original sample a bit, it loads the player on creation, I have a load source and play  button and a remove player button. After I remove the player then click the  'load' button the video plays again but you only hear it as its not in the display list.

                   

                  http://gumbo.flashhub.net/video/ src included

                   

                  press the load(play) then unload then load again....

                   

                  David.

                  • 6. Re: Getting rid of a video
                    toft Level 1

                    Good news and bad news.

                     

                    Good news: I tried using the spark VideoDisplay instead of the mx one and it works !! (Why the #€@ didnt I think of that earler ??)

                     

                    Bad news: Have probably wasted lots of your time...

                     

                    Well, thanks as always David, really appreciate your kind assistance when in flex despair...