3 Replies Latest reply on Dec 13, 2011 1:10 AM by dodge1603

    Paused seek without autoPlay=true in osmf mediaplayer?

    dodge1603

      Hi,

      I'm currently running into an issue where I cannot find a solution. At the moment I'm  implementing a seek for a videoplayer where autoPlay can be false.

      My current solution is to use a wrapped seekTime function which checks if a seekTrait exists. If not, the player sets presetSeekValue and tries to seek again later.

       

      public function seekTime( value:Number ):void {

          // player has to be able to seek within video!

          if ( mediaElement ) {

              if ( mediaElement.hasTrait( MediaTraitType.SEEK ) ) { // mediaElement has seekTrait

                  [..]

                  // do seek processing

                  [..]

              } else {

                  // MediaElement is defined, but is not seekable yet.

                  // Set seek param for next seek and call play to initialize seekable process.

                  presetSeekValue = value;

                  play(); // play media to receive a seekTrait

              }

          } else {

              trace("No seek possible, because there is no mediaElement!");

          }

      }

       

      private function onCanSeekChange( event:MediaPlayerCapabilityChangeEvent ):void {

          mediaPlayer.removeEventListener( MediaPlayerCapabilityChangeEvent.CAN_SEEK_CHANGE, onCanSeekChange );

          if ( event.enabled ) { // seek allowed

              if ( presetSeekValue > 0 ) {

                  seekTime( presetSeekValue );

                  presetSeekValue = -1; // reset value

              } else {

                  // enable seek controlls

              }

          }

      }

       

      My current problem is, that the video needs to start playing before the seeked position can be accessed. Now I need to seek in paused mode without videoplayer playing at the reached seek-position. It's running very well when the videoplayer has been paused playing manually before seeking. Can I get this situation without doing play + seek + watch for playevent + pause? This looks like an ugly workaround and is not working very well every time.

        • 1. Re: Paused seek without autoPlay=true in osmf mediaplayer?
          acon cagua

          Hi,

          I'm not 100% sure if I understand your point correctly, so I'm sorry if this won't help you...

           

          You can preserve the value of mediaPlayer.autoPlay property, then change it as you like (set to false), then seek (player won't start playing), then restore the autoPlay flag (see below).

           

          Jiri

           

           

          var saveAutoPlay:Boolean = mediaPlayer.autoPlay;

          if (mediaPlayer.paused)
              mediaPlayer.autoPlay = false;
          mediaPlayer.seek(seekValue);

          mediaPlayer.autoPlay = saveAutoPlay;

          • 2. Re: Paused seek without autoPlay=true in osmf mediaplayer?
            TheRossman Level 1

            In your code here:

             

            play(); // play media to receive a seekTrait

             

            can you just do a play() then call pause() immediately after that??  I don't know really, but that might fire up the stream and immediately pause it?

             

            play(); // play media to receive a seekTrait

            pause();

            • 3. Re: Paused seek without autoPlay=true in osmf mediaplayer?
              dodge1603 Level 1

              Thank you for your ansers.

              The autoPlay-option is still in use. In some cases the videoplayer has to autostart by default, in other cases it don't have to.

               

              I allready know the play() + pause() trick, but it is not very accurate. In some situations the video cannot pause directly after start (canPause). At the moment my logic runs very good, except seeks to position 0, but why seek to 0 when video has not startet?