You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.7 KiB

  1. # Using the reloadSourceOnError Plugin
  2. Call the plugin to activate it:
  3. ```js
  4. player.reloadSourceOnError()
  5. ```
  6. Now if the player encounters a fatal error during playback, it will automatically
  7. attempt to reload the current source. If the error was caused by a transient
  8. browser or networking problem, this can allow playback to continue with a minimum
  9. of disruption to your viewers.
  10. The plugin will only restart your player once in a 30 second time span so that your
  11. player doesn't get into a reload loop if it encounters non-transient errors. You
  12. can tweak the amount of time required between restarts by adjusting the
  13. `errorInterval` option.
  14. If your video URLs are time-sensitive, the original source could be invalid by the
  15. time an error occurs. If that's the case, you can provide a `getSource` callback
  16. to regenerate a valid source object. In your callback, the `this` keyword is a
  17. reference to the player that errored. The first argument to `getSource` is a
  18. function. Invoke that function and pass in your new source object when you're ready.
  19. ```js
  20. player.reloadSourceOnError({
  21. // getSource allows you to override the source object used when an error occurs
  22. getSource: function(reload) {
  23. console.log('Reloading because of an error');
  24. // call reload() with a fresh source object
  25. // you can do this step asynchronously if you want (but the error dialog will
  26. // show up while you're waiting)
  27. reload({
  28. src: 'https://example.com/index.m3u8?token=abc123ef789',
  29. type: 'application/x-mpegURL'
  30. });
  31. },
  32. // errorInterval specifies the minimum amount of seconds that must pass before
  33. // another reload will be attempted
  34. errorInterval: 5
  35. });
  36. ```