0

We are trying to get our player load from stored time in local storage.

We keep getting this error

Error in "beforePlay" event handler: TypeError: can't access property "seekRange", m is null

The code that loads is the following:

let time = parseFloat(this.stored_time);
jwplayer().on('ready', function(e) {
   jwplayer().on('beforePlay', function(e) {
      jwplayer().seek(time);
   })
})

in the on ready function the player should be ready.

in the play() on beforePlay block works, so the global jwplayer function is avaialbe

jwplayer().on('beforePlay', function(e) {
      jwplayer().play();
})

In the this.stored_time it has values like 1743.616545. I've tried typecasting to Int but no difference the jwplayer().seek(time) throws the error above.

Originally I tried just using the on ready handler; with this the player crashed when jwplayer().seek(time) runs.

Any ideas on how to resolve this?

Regards, Steve

ServerStorm
  • 59
  • 1
  • 9

2 Answers2

0

Hi Can you please check below code.

        const playerInstance = jwplayer('player').setup({
          'playlist': 'https://cdn.jwplayer.com/feeds/DrqpQIzP.rss'
        });

        playerInstance.on('displayClick', playerInstance.pause);

        playerInstance.on('ready', function() {
         
          var playlist = playerInstance.getPlaylist();
          var seconds= parseInt(this.stored_time);
          for (var index = 0; index < playlist.length; index++) {
            var duration = Math.round(playlist[index][' ']);
            if (duration > seconds) {
              playerInstance.playlistItem(index);
              playerInstance.seek(seconds);
              break;
            }
          }
        });
Amol Naik
  • 433
  • 1
  • 8
  • 18
0

Thanks for the response Amol Naik!

I ended up resolving this by doing:

// This occurs just before play, so using play() just initiates this step 
// slightly earlier; a better user experience

    jwplayer().on('beforePlay', function(e){
        jwplayer().play().seek(stored_time).pause();
        jwplayer().pause();
        utils.losChangeColours(stored_time);
    })

The seek() throws an error if used in the paused() state; it must play(). So doing jwplayer().play().seek(time).pause() it will smoothly set the stored time without the appearance of buffering.

Hope this helps someone else.

Steve

ServerStorm
  • 59
  • 1
  • 9