react-player
react-player copied to clipboard
Setting fallback url in onError will throw error
Current Behavior
I'm using manifest files in the player and they are not always compliant so I'm trying to set backup url if an onError is triggered. But as soon as I set a new url, it wouldn't work, it would throw an error again error: e {code: 32, message: 'No streams to play.', data: null}
EDIT: I am using this as a validator of which file I can use later in the app to render. So the modal with video returns working url with onReady() from the ReactPlayer. If I tried to get the url from the instance passed to onReady() it would be an array and not the actual file being rendered.
This is the code:
const [currentUrl, setCurrentUrl] = useState<string>(url);
const onError = (error: any, data: any) => {
if (backupUrl) {
setCurrentUrl(backupUrl);
// setValidationState("Validating backup media file...");
}
};
// then later in return ()
{
ReactPlayer.canPlay(currentUrl) ? (
<ReactPlayer
url={currentUrl}
loop={true}
muted={true}
controls={true}
onError={(e, d) => onError(e, d)}
onReady={(p) => onReady(p)} />
) : null
}
If I try to insert the backup right away (mp4 file) it works np, also when I insert an array of both the mpd and mp4 it works correctly.
Expected Behavior
Setting a new url in onError would actually process and play the video correctly.