Skip to content

Commit

Permalink
fix: generates new preview image on playerPoster change (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dvir Hazout authored and Dan Ziv committed Oct 10, 2017
1 parent c137670 commit 504d341
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/components/seekbar/seekbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ class SeekBarControl extends Component {
*/
componentDidUpdate() {
if (this.props.playerPoster && !this.framePreviewImg) {
this.framePreviewImg = this.getFramePreviewImg();
this.framePreviewImg = this.getFramePreviewImg(this.props.playerPoster);
}
}

/**
* before component update, check if the player poster changed and create new preview image url.
*
* @param {any} nextProps props for the next component update
* @returns {void}
* @memberof SeekBarControl
*/
componentWillUpdate(nextProps: any) {
if(this.props.playerPoster !== nextProps.playerPoster) {
this.framePreviewImg = this.getFramePreviewImg(nextProps.playerPoster);
}
}

Expand Down Expand Up @@ -296,15 +309,16 @@ class SeekBarControl extends Component {
/**
* get the frame preview sprite based on player poster
*
* @param {string} posterUrl poster url
* @returns {string} image url
* @memberof SeekBarControl
*/
getFramePreviewImg(): string {
let parts = this.props.playerPoster.split('/');
getFramePreviewImg(posterUrl: string): string {
let parts = posterUrl.split('/');
let heightValueIndex = parts.indexOf('height') + 1;
let widthValueIndex = parts.indexOf('width') + 1;
parts[heightValueIndex] = 90;
parts[widthValueIndex] = 160;
parts[heightValueIndex] = '90';
parts[widthValueIndex] = '160';
parts.push('vid_slices/100');

return parts.join('/');
Expand Down

0 comments on commit 504d341

Please sign in to comment.