user2587454
user2587454

Reputation: 913

using videojs with hls catch 403

my site is using token to play video files and in case of expired token the file request response is 403.

i need to catch the 403 using videojs and hls to create a new token.

i tried with videojs on player error:

player.on('error', function(){})

but this one is not catching 403.

is there a way to catch the HLS errors and not the video?

Upvotes: 1

Views: 2906

Answers (1)

Rory Donohue
Rory Donohue

Reputation: 438

For anyone still struggling with this, VideoJs now has a reloadSourceOnError plugin that can catch these events.

player.reloadSourceOnError({

  // getSource allows you to reload the source object after an error
  getSource: (reload) => {
     console.log('Perform any auth renewal / asset URL regeneration here ');

    /* Call reload() with a fresh source object, asynchronously if you
     * want (but the error dialog will show up while you're waiting) */
    reload({
       src: 'https://example.com/index.m3u8?CloudFront-Policy=xxxx',
       type: 'application/x-mpegURL'
    });
  },

  /* Minimum amount of seconds that must pass before another reload
   * will be attempted, stops cascading errors */
  errorInterval: 5
});

Upvotes: 3

Related Questions