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

Loop when player is running #257

Merged
merged 2 commits into from
Oct 24, 2017
Merged
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
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