Skip to content

Commit

Permalink
Merge pull request #257 from SkinyMonkey/feature-loop_on_fly
Browse files Browse the repository at this point in the history
Loop when player is running
  • Loading branch information
SkinyMonkey authored and cookpete committed Oct 24, 2017
1 parent 633aa39 commit abd2096
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class ReactPlayer extends Component {
return (
this.props.url !== nextProps.url ||
this.props.playing !== nextProps.playing ||
this.props.loop !== nextProps.loop ||
this.props.volume !== nextProps.volume ||
this.props.muted !== nextProps.muted ||
this.props.playbackRate !== nextProps.playbackRate ||
Expand Down
18 changes: 15 additions & 3 deletions src/demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default class App extends Component {
played: 0,
loaded: 0,
duration: 0,
playbackRate: 1.0
playbackRate: 1.0,
loop: false
}
load = url => {
this.setState({
Expand All @@ -41,6 +42,9 @@ export default class App extends Component {
stop = () => {
this.setState({ url: null, playing: false })
}
toggleLoop = () => {
this.setState({ loop: !this.state.loop })
}
setVolume = e => {
this.setState({ volume: parseFloat(e.target.value) })
}
Expand Down Expand Up @@ -97,7 +101,7 @@ export default class App extends Component {
}
render () {
const {
url, playing, volume, muted,
url, playing, volume, muted, loop,
played, loaded, duration,
playbackRate,
soundcloudConfig,
Expand All @@ -119,6 +123,7 @@ export default class App extends Component {
height='100%'
url={url}
playing={playing}
loop={loop}
playbackRate={playbackRate}
volume={volume}
muted={muted}
Expand All @@ -132,7 +137,7 @@ export default class App extends Component {
onPause={this.onPause}
onBuffer={() => console.log('onBuffer')}
onSeek={e => console.log('onSeek', e)}
onEnded={() => this.setState({ playing: false })}
onEnded={() => this.setState({ playing: loop })}
onError={e => console.log('onError', e)}
onProgress={this.onProgress}
onDuration={duration => this.setState({ duration })}
Expand Down Expand Up @@ -172,6 +177,13 @@ export default class App extends Component {
</label>
</td>
</tr>
<tr>
<td>
<label>
<input type='checkbox' checked={loop} onChange={this.toggleLoop} /> Loop
</label>
</td>
</tr>
<tr>
<th>Played</th>
<td><progress max={1} value={played} /></td>
Expand Down
3 changes: 2 additions & 1 deletion src/players/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default class Base extends Component {
}
}
shouldComponentUpdate (nextProps) {
return this.props.url !== nextProps.url
return this.props.url !== nextProps.url ||
this.props.loop !== nextProps.loop
}
callPlayer (method, ...args) {
// Util method for calling a method on this.player
Expand Down

0 comments on commit abd2096

Please sign in to comment.