Skip to content

Added errorMessage and catchError props #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.9.1 (27-03-2023)

Added `errorMessage` prop to customize error message shown in Video Player UI

Added `catchError` prop to handle `react-native-video` lib error while also using error handling mechanism provided by `react-native-video-controls` lib

## 2.5.1 (17-05-2020)

[#177](https://github.com/itsnubix/react-native-video-controls/pull/177)
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ In addition, the `<VideoPlayer />` also takes these props:
| seekColor | String(#HEX) | '#FFF' | Fill/handle colour of the seekbar |
| style | StyleSheet | null | React Native StyleSheet object that is appended to the video's parent `<View>` |
| tapAnywhereToPause | Boolean | false | If true, single tapping anywhere on the video (other than a control) toggles between playing and paused. |

| showTimeRemaining | Boolean | true | If true, show the time remaing, else show the current time in the Player.
`<View>`

| showHours | Boolean | false | If true, convert time to hours in the Player
`<View>`
| showTimeRemaining | Boolean | true | If true, show the time remaining, else show the current time in the Player `<View>` |
| showHours | Boolean | false | If true, convert time to hours in the Player `<View>` |
| errorMessage | String | 'Video unavailable' | Error message to show in Video Player UI when error occurs |

### Events

Expand All @@ -85,7 +82,8 @@ These are various events that you can hook into and fire functions on in the com
| onExitFullscreen | Fired when the video exits fullscreen after the fullscreen button is pressed |
| onHideControls | Fired when the controls disappear |
| onShowControls | Fired when the controls appear |
| onError | Fired when an error is encountered when loading the video |
| onError | Fired when an error is encountered when loading the video. This prop overrides error handling mechanism provided by this library |
| catchError | Fired when an error is encountered when loading the video |
| onPause | Fired when the video is paused after the play/pause button is pressed |
| onPlay | Fired when the video begins playing after the play/pause button is pressed |
| onBack | Function fired when back button is pressed, override if using custom navigation |
Expand Down
6 changes: 5 additions & 1 deletion VideoPlayer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ interface VideoPlayerProperties extends VideoProperties {
style?: StyleProp<ViewStyle>;
/** If true, single tapping anywhere on the video (other than a control) toggles between playing and paused. */
tapAnywhereToPause?: boolean;
/** Custom error message to show in Video Player UI */
errorMessage?: string;
/** Fired when the video enters fullscreen after the fullscreen button is pressed */
onEnterFullscreen?: () => void;
/** Fired when the video exits fullscreen after the fullscreen button is pressed */
Expand All @@ -37,8 +39,10 @@ interface VideoPlayerProperties extends VideoProperties {
onHideControls?: () => void;
/** Fired when the controls appear */
onShowControls?: () => void;
/** Fired when an error is encountered when loading the video */
/** Fired when an error is encountered when loading the video. This overrides error handling mechanism provided by react-native-video-controls lib */
onError?: (error: LoadError) => void;
/** Fired when an error is encountered when loading the video. This does not overrides error handling mechanism provided by react-native-video-controls lib */
catchError?: (error: LoadError) => void;
/** Fired when the video is paused after the play/pause button is pressed */
onPause?: () => void;
/** Fired when the video begins playing after the play/pause button is pressed */
Expand Down
6 changes: 5 additions & 1 deletion VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ export default class VideoPlayer extends Component {
state.loading = false;

this.setState(state);

if (typeof this.props.catchError === "function") {
this.props.catchError(err);
}
}

/**
Expand Down Expand Up @@ -1199,7 +1203,7 @@ export default class VideoPlayer extends Component {
source={require('./assets/img/error-icon.png')}
style={styles.error.icon}
/>
<Text style={styles.error.text}>Video unavailable</Text>
<Text style={styles.error.text}>{this.props.errorMessage || 'Video unavailable'}</Text>
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-video-controls",
"version": "2.8.1",
"version": "2.9.1",
"description": "A set of GUI controls for the react-native-video component",
"license": "MIT",
"main": "VideoPlayer.js",
Expand Down