googleads / videojs-ima

IMA SDK Plugin for Video.js
Apache License 2.0
445 stars 285 forks source link

iOS bug cannot set currentTime(0) inside loadedmetadata event #1148

Open dioramayuanito opened 3 weeks ago

dioramayuanito commented 3 weeks ago
/**
 * Changes the player source.
 * @param {?string} contentSrc The URI for the content to be played. Leave
 *     blank to use the existing content.
 */
PlayerWrapper.prototype.changeSource = function (contentSrc) {
  // Only try to pause the player when initialised with a source already
  if (this.vjsPlayer.currentSrc()) {
    this.vjsPlayer.currentTime(0);
    this.vjsPlayer.pause();
  }
  if (contentSrc) {
    this.vjsPlayer.src(contentSrc);
  }
  this.vjsPlayer.one('loadedmetadata', this.seekContentToZero.bind(this));
};

/**
 * Seeks content to 00:00:00. This is used as an event handler for the
 * loadedmetadata event, since seeking is not possible until that event has
 * fired.
 */
PlayerWrapper.prototype.seekContentToZero = function () {
  this.vjsPlayer.currentTime(0);
};

this.vjsPlayer.one('loadedmetadata', this.seekContentToZero.bind(this)); sometimes will be failed because of iOS bug

https://stackoverflow.com/questions/18266437/html5-video-currenttime-not-setting-properly-on-iphon