1 Reply Latest reply on Aug 13, 2009 2:02 PM by chadillac83

    VideoDisplay plays Video -> show Canvas -> VideoDisplay plays another Video, but first Frames are always from "old" videofile.why?

    sirk214 Level 1

      Hi guys,

      As described in the topic, I have a VideoDisplay Component which shows a video (1stVideo). On video end, it shows an screen (canvas, image..) and after user is ready with the screen, it shows another video (2ndVideo) in the same VideoDisplay Component than before.

       

      Problem is, that you see always the startpicture from the 1stVideo for maybe 1-2 frames, before the 2nd Video starts. This is only a little problem, but it goes on my nerves.

       

      I'm working with visible.

       

      VideoDisplay.source = 1stVideo.flv;

      VideoDisplay.play();

       

      On VideoEnd, the player throws an Event, which shows another component (f.e. canvas or image.)

      (..)

      VideoDisplay.visible = false;

      //I tried to reset the source, but this doesn't work

      //VideoDisplay.source = ""

      SomeCanvas.visible = true;

       

      After User Action, Videodisplay shows another Video

      SomeCanvs.visible = false;

      VideoDisplay.source = 2ndVideo.flv

      VideoDisplay.play();

      VideoDisplay.visible=true;

       

      Has anybody a solution for that problem or can tell me why it still shows the startframe, even if the source is reset and 2nd video plays before VideoDisplay is visible again? Or is the compiler just faster than the reaction of the program? I'm confused and grateful for every idea!

        • 1. Re: VideoDisplay plays Video -> show Canvas -> VideoDisplay plays another Video, but first Frames are always from "old" videofile.why?
          chadillac83

          not sure if it's related but I know the Video.clear() functionality is borked in Flex 3.  To get around it we wrote a custom video display component (this isnt't the only reason we used it, VideoDisplay components don't utilize NetConnections very wisely IMO because every netstream you create using one spawns a new NC to your FMS server... which is lame) and it uses the Video component itself.

           

          feel free to use/modify as you see fit.

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initComponent()">
              <mx:Script>
                  <![CDATA[
                      import mx.events.IndexChangedEvent;
                  
                      import flash.media.Video;
                      import flash.media.SoundTransform;
                      import mx.core.UIComponent;
                      import mx.core.Application;
                      import mx.controls.Alert;
                      
                      public var UIComp:UIComponent;
                      public var video:Video;
                      public var webcam:Boolean;
                      public var hideVideo:Boolean;
                      public var netStream:NetStream;
                      public var streamId:String;
                      
                      private var _audio:SoundTransform;
                      private var _webCam:Camera;
                      private var _attached:Boolean;
                      private var _connection_attempts:int = 0;
                      private var _my_timeout_id:int;
                      
                  
                      private function initComponent():void
                      {
                          UIComp = new UIComponent();
                          
                          this.video = new Video(this.height, this.width);
                          
                          this.video.width = this.width;
                          this.video.height = this.height;
                          this.video.smoothing = true;
                          
                          UIComp.addChild(this.video);
                          
                          this.addChild(UIComp);
                          
                          if(webcam == true)
                          {
                              if(hideVideo)
                              {
                                  video.visible = false;
                              }
                          }
                      }
                      
                      public function clear():void
                      {
                          // broken... don't even bother using it... use clear_hack() instead.
                          this.video.clear();
                      }
                      
                      public function clear_hack():void
                      {    
                          // as3 video.clear() = broken... this is a hack. - Chad
                          UIComp.removeChild(this.video);
                          
                          this.video = new Video(this.height, this.width);
                          
                          this.video.width = this.width;
                          this.video.height = this.height;
                          this.video.smoothing = true;
                          
                          UIComp.addChild(this.video);
                          
                          if(webcam == true)
                          {
                              if(hideVideo)
                              {
                                  video.visible = false;
                              }
                          }
                      }
                      
                      public function attachMyCamera():void
                      {
                          _webCam = Camera.getCamera();
                          //_webCam.setQuality( 0, 0);
                          //_webCam.setMode(this.width, this.height, 20);
                          
                          this.video.attachCamera(_webCam);
                      }
                      
                      public function openStream(duid:String):void
                      {
                          if(this.netStream)
                          {
                              closeStream();
                              this.netStream = null;
                              this._audio = null;
                          }
                          
                          clear_hack();
                          
                          if(duid != 'true')
                          {
                              this.streamId = duid;
                          }
                          
                          if(!Application.application.stream.connected)
                          {
                              if(_connection_attempts <= 4)
                              {
                                 if(_my_timeout_id)
                                 {
                                     clearTimeout(_my_timeout_id);
                                 }
                                 
                                 _connection_attempts++;
                                 Application.application.connectStream();
                                 _my_timeout_id = setTimeout(openStream, 10000, duid);
                                 return;
                              }
                              else if(_connection_attempts >= 5)
                              {
                                  Alert.show("We're having problems connecting to the stream server after multiple attempts.  Please try again later.  Sorry.","Stream Server Connection Failures");
                                  _connection_attempts = 0;
                                  return;
                              }
                          }
                          
                          this.netStream = new NetStream(Application.application.stream);
                          this.netStream.addEventListener(NetStatusEvent.NET_STATUS, handleNetStatus);
                          this.netStream.play(this.streamId);
                          
                          this._audio = new SoundTransform(0,0);
                          this.netStream.soundTransform = this._audio;
                          
                          this.video.attachNetStream(this.netStream);
                          this.video.visible = true;
                          this._attached = true;
                          _connection_attempts = 0;
                      }
                      
                      public function handleNetStatus(event:NetStatusEvent):void
                      {
                          if(Application.application.debugging_stream)
                          {
                              var log_msg:Object = {'event object:':event.info, 'NETSTREAM EVENT FROM ':this.parent+'->'+this.name};
                              Application.application.debug.log(log_msg);
                          }
                      }
                      
                      public function closeStream(hideVideo:Boolean = true):void
                      {
                          if(this.netStream)
                          {
                              this.netStream.soundTransform = null;
                              this._audio = null;
                              this.netStream.close();
                          }
                          
                          if(this.video)
                          {
                              if(hideVideo) {
                                  this.video.visible = false;
                              }
                          }
                      }
                      
                      public function set setVolume(soundValue:Number):void
                      {
                          // yeah it's gay, we know.
                          var audio:SoundTransform = this.netStream.soundTransform;
                              audio.volume = soundValue;
                              
                          this.netStream.soundTransform = audio;
                      }
                      
                      public function set setAttached(isAttached:Boolean):void
                      {
                           if(isAttached)
                           {
                               this.video.attachNetStream(this.netStream);
                           }
                           else
                           {
                               this.video.attachNetStream(null);
                           }
                           
                           this._attached = isAttached;
                      }
                      
                      public function get attached():Boolean
                      {
                           return this._attached;
                      }
                      
                  ]]>
              </mx:Script>
          </mx:Canvas>