Skip to content
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

Added the ability to place a custom thumbnail while loading instead of the spinning loader #265

Open
wants to merge 2 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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ 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. |
| showHours | Boolean | false | If true, convert time to hours in the Player. |
| thumbnailUri | Boolean | String | URI string pointing to an image to be displayed as a loader instead of the default spinning loader |
| thumbnailStyle | StyleSheet | null | React Native StyleSheet object that is appended to the loader thumbnail |


| 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>`

### Events

Expand Down
26 changes: 24 additions & 2 deletions VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export default class VideoPlayer extends Component {
muted: this.props.muted,
volume: this.props.volume,
rate: this.props.rate,
//thumbnail uri
thumbnailUri: this.props.thumbnailUri,

// Controls

isFullscreen:
Expand Down Expand Up @@ -158,6 +161,7 @@ export default class VideoPlayer extends Component {
this.styles = {
videoStyle: this.props.videoStyle || {},
containerStyle: this.props.style || {},
thumbnailStyle: this.props.thumbnailStyle || {},
};
}

Expand All @@ -184,11 +188,15 @@ export default class VideoPlayer extends Component {
/**
* When load starts we display a loading icon
* and show the controls.
* If the user wants to display a thumbnail instead,
* the animation does not start.
*/
_onLoadStart() {
let state = this.state;
state.loading = true;
this.loadAnimation();
if (!this.state.thumbnailUri){
this.loadAnimation();
}
this.setState(state);

if (typeof this.props.onLoadStart === 'function') {
Expand Down Expand Up @@ -753,6 +761,10 @@ export default class VideoPlayer extends Component {
if (this.styles.containerStyle !== nextProps.style) {
this.styles.containerStyle = nextProps.style;
}

if (this.styles.thumbnailStyle !== nextProps.style) {
this.styles.thumbnailStyle = nextProps.style;
}
}

/**
Expand Down Expand Up @@ -1163,10 +1175,20 @@ export default class VideoPlayer extends Component {
}

/**
* Show loading icon
* Show loading icon or thumbnail
*/
renderLoader() {
if (this.state.loading) {
if (this.state.thumbnailUri) {
return (
<View style={styles.loader.container}>
<Image
source={{uri: this.state.thumbnailUri}}
style={[this.styles.thumbnailStyle]}
/>
</View>
)
}
return (
<View style={styles.loader.container}>
<Animated.Image
Expand Down