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