UNPKG

1.69 kBMarkdownView Raw
1# Using the reloadSourceOnError Plugin
2Call the plugin to activate it:
3
4```js
5player.reloadSourceOnError()
6```
7Now if the player encounters a fatal error during playback, it will automatically
8attempt to reload the current source. If the error was caused by a transient
9browser or networking problem, this can allow playback to continue with a minimum
10of disruption to your viewers.
11
12The plugin will only restart your player once in a 30 second time span so that your
13player doesn't get into a reload loop if it encounters non-transient errors. You
14can tweak the amount of time required between restarts by adjusting the
15`errorInterval` option.
16
17If your video URLs are time-sensitive, the original source could be invalid by the
18time an error occurs. If that's the case, you can provide a `getSource` callback
19to regenerate a valid source object. In your callback, the `this` keyword is a
20reference to the player that errored. The first argument to `getSource` is a
21function. Invoke that function and pass in your new source object when you're ready.
22
23```js
24player.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```