3 Replies Latest reply on Feb 26, 2010 12:09 PM by kglad

    Autoplay Video Start at Specified Point

    seansks

      Hi, I'm hoping someone can assist me in making a change to my Actions. Basically the code below has been designed so that a video starts at 52 seconds (rather than the beginning) when you press play. It works good right now, starts where it's supposed to, but I want to change the code so that it autoplays the video starting at 52 seconds. The problem with this though, is that when I try and set it for autoplay, the video starts at the beginning and doesn't wait for it to load to 52 seconds before it autoplays. Any input on the coding? I need it just so that the autoplay doesn't kick in until the video is loaded to the 52 second point. Thank you in advance! Beyond appreciated!

       

       

       

      import fl.video.MetadataEvent;
      import fl.video.VideoProgressEvent;

       

      import fl.video.*;

       

      my_FLVPlybk.addEventListener(VideoEvent.COMPLETE, rewind);
      function rewind(eventObject:VideoEvent):void {
          my_FLVPlybk.seek(52);
          my_FLVPlybk.play();

       

      }

       

      var fp:FLVPlayback = my_FLVPlybk;
      fp.addEventListener(VideoProgressEvent.PROGRESS, videoProgressHandler, false, 0, true);
      fp.addEventListener(MetadataEvent.METADATA_RECEIVED, metaDataHandler, false, 0, true);
      fp.autoPlay = true;

       

      var startSeekTime:Number = 52;
      var videoDuration:Number;
      var videoSeeked:Boolean = false;

       

      function metaDataHandler(event:MetadataEvent):void {
           if(event.info.duration != null){
                videoDuration =event.info.duration;
           }  
      }

       

      function videoProgressHandler(event:VideoProgressEvent):void {
           var fp:FLVPlayback = event.currentTarget as FLVPlayback;
           var bytesLoaded:Number = event.bytesLoaded;
           var bytesTotal:Number = event.bytesTotal;
           if( !isNaN(videoDuration)){

       

                if( (bytesLoaded/bytesTotal) >= ( (startSeekTime+4)/videoDuration) && !videoSeeked ){

       

                     videoSeeked = true;
                     fp.seek(startSeekTime);
                }
           }
      }

        • 1. Re: Autoplay Video Start at Specified Point
          kglad Adobe Community Professional & MVP

          disable autoPlay and, when loading is complete, execute your seek() method and then your play() method.

          1 person found this helpful
          • 2. Re: Autoplay Video Start at Specified Point
            seansks Level 1

            Would there be a way for you to paste my code with the edits i would need to do?

            Not sure exactly what to do to execute the seek() method and then the play() method.

            • 3. Re: Autoplay Video Start at Specified Point
              kglad Adobe Community Professional & MVP

              use:

               


               

               

              import fl.video.MetadataEvent;
              import fl.video.VideoProgressEvent;

               

              import fl.video.*;

               

              my_FLVPlybk.addEventListener(VideoEvent.COMPLETE, rewind);
              function rewind(eventObject:VideoEvent):void {
                  my_FLVPlybk.seek(52);
                  my_FLVPlybk.play();

               

              }

               

              var fp:FLVPlayback = my_FLVPlybk;
              fp.addEventListener(VideoProgressEvent.PROGRESS, videoProgressHandler, false, 0, true);
              fp.addEventListener(MetadataEvent.METADATA_RECEIVED, metaDataHandler, false, 0, true);
              fp.autoPlay = false;

               

              var startSeekTime:Number = 52;
              var videoDuration:Number;
              var videoSeeked:Boolean = false;

               

              function metaDataHandler(event:MetadataEvent):void {
                   if(event.info.duration != null){
                        videoDuration =event.info.duration;
                   }  
              }

               

              function videoProgressHandler(event:VideoProgressEvent):void {
                   var fp:FLVPlayback = event.currentTarget as FLVPlayback;
                   var bytesLoaded:Number = event.bytesLoaded;
                   var bytesTotal:Number = event.bytesTotal;
                   if( !isNaN(videoDuration)){

               

                        if( (bytesLoaded/bytesTotal) >= ( (startSeekTime+4)/videoDuration) && !videoSeeked ){

               

                             videoSeeked = true;
                             fp.seek(startSeekTime);

              fp.play();

                        }
                   }
              }