Gary Carlyle Cook
Gary Carlyle Cook

Reputation: 749

VOD seeking with Bitmovin player

I am trying to display VOD with a predetermined start time but I can't find how to do this. The Bitmovin website lists the player API functions but does not really have any tutorials how to use them all.

I have Included SEEK but I don't know why it is not working?

It plays the video but starts on 0 secs rather than 40 secs.

<div id="player"></div>
      <script type="text/javascript">
          var conf = {
              key:       "XXXXXXXXXXXXXXXXXXXX",

              source: {

                progressive:        "http://example.com/somevid.mp4",
                poster:         "http://example.com/someimage.jpg",
              },

                    playback : {
  autoplay         : true,
  seek: 40,
},

events: {

  onPlay                  : function() {
              //  alert("I am Playing!");

                            },

},

          };
          var player = bitdash('player');
          player.setup(conf).then(function(value) {
              // Success
              console.log('Successfully created bitdash player instance');
          }, function(reason) {
              // Error!
              console.log('Error while creating bitdash player instance');
          });
      </script>

Upvotes: 0

Views: 1661

Answers (4)

Mohammed Yousuff
Mohammed Yousuff

Reputation: 326

got into this issue recently there due to version updates above given code didn't worked for me so i come up with below code.

const playerConfig = {
 key: "abcxyz",
 ui: false,
 playback: {
  muted: true,
  autoplay: true
 },
 events: {
  //will start playback again when video finishes playing
  playbackfinished: function () {
    this.play();
  }
 }

};

Upvotes: 0

Ansar Ahmed
Ansar Ahmed

Reputation: 31

Like Stefan mention using seek() directly inside onReady it worked for me. Even though my problem was different autoplay was not working in IE11 Win7 i used below hack to forcefully start it.

events: {
   onReady: function() {
     this.seek(0);
  }
}

Upvotes: 0

jmsn
jmsn

Reputation: 1080

In the player configuration you could specify a callback function for when the playback starts (onPlay) and inside this function seek to the desired position in seconds by using the seek(pos) player API function.

For example:

var conf = {
    key:"XXXXXXXXXXXXXXXXXXXX",
    source: {
        progressive: "http://example.com/somevid.mp4",
        poster:      "http://example.com/someimage.jpg",
    },
    playback: {
        autoplay: true
    },
    events: {
        onPlay: function() {
            // seek to desired start position
            this.seek(40);
        }
    }
};

Side note: Inside event callbacks the this keyword is bound to the player object.

EDIT:

The previous approach will seek to second 40 also every time the user pauses playback and then continues playback again, because the onPlay event is triggered every time the user continues playback. To avoid this a better approach would be:

var conf = {
    key:"XXXXXXXXXXXXXXXXXXXX",
    source: {
        progressive: "http://example.com/somevid.mp4",
        poster:      "http://example.com/someimage.jpg",
    },
    playback: {
        autoplay: true
    },
    events: {
        onReady: function() {
            this.addEventHandler('onPlay', seekToStart);
        }
    }
};

function seekToStart() {
    // remove event handler after first seek to avoid seeking 
    // to specified the position when user pauses and plays again
    this.removeEventHandler('onPlay', seekToStart);

    // seek to desired start position
    this.seek(40);
}

Upvotes: 1

Alexander Wolf
Alexander Wolf

Reputation: 604

To the best of my knowledge, the "seek" attribute is not valid in the player configuration - it is not stated in the documentation as well. So, to achieve the desired behaviour, you most likely have to use the API and call the .seek(x) command on the player instance.

But there might be another way of doing this. Maybe it would be best to get in touch with Bitmovin directly - I found their support team to be very responsive.

Upvotes: 2

Related Questions