Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Milloy committed Nov 15, 2016
1 parent bab2c83 commit 8f86c50
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
### Features:

- Added loading icon
- Add error handling, ref: [Issue #4](https://github.com/itsnubix/react-native-video-controls/issues/4)
44 changes: 41 additions & 3 deletions VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class VideoPlayer extends Component {
seeking: false,
loading: false,
currentTime: 0,
error: false,
duration: 0,
};

Expand Down Expand Up @@ -191,9 +192,12 @@ export default class VideoPlayer extends Component {
* Here we display a simple error saying
* the video failed to load.
*/
_onError() {
// TODO
// handle errors...
_onError( err ) {
console.log( 'VideoPlayer: There was an error during playback', err );
let state = this.state;
state.error = true;
state.loading = false;
this.setState( state );
}

/**
Expand Down Expand Up @@ -927,6 +931,20 @@ export default class VideoPlayer extends Component {
return null;
}

renderError() {
if ( this.state.error ) {
return (
<View style={ styles.error.container }>
<Image source={ require( './assets/img/error-icon.png' ) } style={ styles.error.icon } />
<Text style={ styles.error.text }>
Video unavailable
</Text>
</View>
);
}
return null;
}

/**
* Provide all of our options and render the whole component.
*/
Expand Down Expand Up @@ -960,6 +978,7 @@ export default class VideoPlayer extends Component {

source={ this.props.source }
/>
{ this.renderError() }
{ this.renderTopControls() }
{ this.renderLoader() }
{ this.renderBottomControls() }
Expand Down Expand Up @@ -989,6 +1008,25 @@ const styles = {
left: 0,
},
}),
error: StyleSheet.create({
container: {
backgroundColor: 'rgba( 0, 0, 0, 0.5 )',
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
justifyContent: 'center',
alignItems: 'center',
},
icon: {
marginBottom: 16,
},
text: {
backgroundColor: 'transparent',
color: '#f27474'
},
}),
loader: StyleSheet.create({
container: {
position: 'absolute',
Expand Down
Binary file added assets/img/error-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/error-icon@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/error-icon@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f86c50

Please sign in to comment.