2 Replies Latest reply on Aug 24, 2010 1:06 AM by dodge1603

    Doing seek before movie has started?

    dodge1603

      Hallo,

      I hope that somebody is able to help me with this problem, because I did spend a lot time trying to solve this.

       

      The point is to start a video at a specific time, but not creating a subclip. This option I allready know, but I have to use a whole movie to work with.

      At the moment I'm using a loop which is checking if a SeekTrait exists and then performs the seek. But in some cases the function does not find a SeekTrait even at the 30th loop. So the video jumps to point 0, which is not the solution I was looking for.

       

      --------

      <code>

      public function trySeekTime( value:Number ):void {
          if ( trySeekTimer ) {
              trySeekTimer.stop();
              trySeekTimer.removeEventListener( TimerEvent.TIMER, onSeekTimer );
          }
                 
          trySeekTimeValue = value;
          trySeekTimer = new Timer( TRY_SEEK_TIMER_DELAY );
          trySeekTimer.addEventListener( TimerEvent.TIMER, onSeekTimer );
          trySeekLoopIndex = 0;
          trySeekTimer.start();
      }
             
      private function onSeekTimer( event:TimerEvent ):void {
          if ( !seeking && ( lastSeekValue != trySeekTimeValue ) ) { // only seek when not seeking the same value at the moment
              seekTime( trySeekTimeValue );
          }
                 
          trySeekLoopIndex++;
          if ( trySeekLoopIndex > TRY_SEEK_MAX_LOOP ) { // when this maximum is reached, stop seeking
              onTimerSeekComplete( null );
          }
      }

       

      /**
      * Seek video position by passing the time value in seconds.
      *
      * @param value time is seconds
      */
      public function seekTime( value:Number ):void {
          seeking = true;
          var mediaSeek : SeekTrait = mediaPlayer.media.getTrait( MediaTraitType.SEEK ) as SeekTrait;
          if ( mediaSeek) { // seek object existing
              if ( mediaSeek.canSeekTo( value ) ) {
                  mediaSeek.addEventListener( SeekEvent.SEEKING_CHANGE, onMediaSeekTimeChange );
                  mediaSeek.seek( value );
                  lastSeekValue = value;
              }
          } else {
              seeking = false;
              dispatchEvent( new Event( "onSeekFailed" ) );
          }
      }

      </code>

      Especially when using rtmp there should be a easy solution to offer this functionality. I think, I'm not the first one who is looking for a solution for starting at time x.

       

      Excluding this point I'm very satisfied with the OSMF, thank you very much for all the work. I guess the solution is somewhere in the VideoElement or DynamicStreaming object.

       

      Thank you very much,


      Chris