Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit d5c6487

Browse files
feat(switchItemOnError): Add option to switch item on error
1 parent 83c1fa3 commit d5c6487

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,21 @@ meisterPlayer.setItem({
8383

8484
meisterPlayer.load();
8585
```
86+
87+
### switchItemOnError *[Boolean]* (default: true) ###
88+
89+
Goes to the next item in the 'sources' array when the current item has thrown an error. (NOT_FOUND, CODEC_ERRORS, etc)
90+
This can be usefull for codecs that cannot be determined if it can play on the current device.
91+
Multisource will switch out the item with a new item so playback can continue.
92+
93+
Example:
94+
95+
``` JavaScript
96+
meisterPlayer.setItem({
97+
sources: [ ... ],
98+
type: 'multi-source',
99+
switchItemOnError: false, // Will stop playback after an fatal error occured.
100+
});
101+
```
102+
103+

src/js/MultiSource.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class MultiSource extends Meister.ParserPlugin {
5656
process(item) {
5757
this.currentItem = item;
5858

59+
// Set default config
60+
if (typeof this.currentItem.switchItemOnError === 'undefined') {
61+
this.currentItem.switchItemOnError = true;
62+
}
63+
5964
return new Promise((resolve, reject) => {
6065
const hasDRM = typeof item.drmConfig === 'object';
6166
item.sources = this.restructureItems(item.sources, hasDRM); // eslint-disable-line
@@ -68,7 +73,9 @@ class MultiSource extends Meister.ParserPlugin {
6873
newItem.metadata = item.metadata; // eslint-disable-line
6974
}
7075

71-
this.on('playerError', this.onPlayerError.bind(this));
76+
if (this.currentItem.switchItemOnError) {
77+
this.on('playerError', this.onPlayerError.bind(this));
78+
}
7279

7380
resolve(newItem);
7481
}

0 commit comments

Comments
 (0)