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

PlaybackRate change feature #123

Closed
wants to merge 2 commits into from
Closed
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 @@ -23,6 +23,7 @@ export default class ReactPlayer extends Component {
this.props.url !== nextProps.url ||
this.props.playing !== nextProps.playing ||
this.props.volume !== nextProps.volume ||
this.props.playbackRate !== nextProps.playbackRate ||
this.props.height !== nextProps.height ||
this.props.width !== nextProps.width ||
this.props.hidden !== nextProps.hidden
Expand Down
12 changes: 11 additions & 1 deletion src/demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default class App extends Component {
volume: 0.8,
played: 0,
loaded: 0,
duration: 0
duration: 0,
playbackRate: 1.0
}
load = url => {
this.setState({
Expand All @@ -34,6 +35,10 @@ export default class App extends Component {
setVolume = e => {
this.setState({ volume: parseFloat(e.target.value) })
}
setPlaybackRate = e => {
console.log(parseFloat(e.target.value))
this.setState({ playbackRate: parseFloat(e.target.value) })
}
onSeekMouseDown = e => {
this.setState({ seeking: true })
}
Expand Down Expand Up @@ -71,6 +76,7 @@ export default class App extends Component {
const {
url, playing, volume,
played, loaded, duration,
playbackRate,
soundcloudConfig,
vimeoConfig,
youtubeConfig,
Expand All @@ -89,6 +95,7 @@ export default class App extends Component {
height={270}
url={url}
playing={playing}
playbackRate={playbackRate}
volume={volume}
soundcloudConfig={soundcloudConfig}
vimeoConfig={vimeoConfig}
Expand All @@ -111,6 +118,9 @@ export default class App extends Component {
<td>
<button onClick={this.stop}>Stop</button>
<button onClick={this.playPause}>{playing ? 'Pause' : 'Play'}</button>
<button onClick={this.setPlaybackRate} value={1}>1</button>
<button onClick={this.setPlaybackRate} value={1.5}>1.5</button>
<button onClick={this.setPlaybackRate} value={2}>2</button>
</td>
</tr>
<tr>
Expand Down
7 changes: 5 additions & 2 deletions src/players/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Base extends Component {
this.mounted = false
}
componentWillReceiveProps (nextProps) {
const { url, playing, volume } = this.props
const { url, playing, volume, playbackRate } = this.props
// Invoke player methods based on incoming props
if (url !== nextProps.url && nextProps.url) {
this.seekOnPlay = null
Expand All @@ -38,6 +38,8 @@ export default class Base extends Component {
this.pause()
} else if (volume !== nextProps.volume) {
this.setVolume(nextProps.volume)
} else if (playbackRate !== nextProps.playbackRate) {
this.setPlaybackRate(nextProps.playbackRate)
}
}
shouldComponentUpdate (nextProps) {
Expand All @@ -53,8 +55,9 @@ export default class Base extends Component {
}
}
onPlay = () => {
const { volume, onStart, onPlay, onDuration } = this.props
const { volume, onStart, onPlay, onDuration, playbackRate } = this.props
if (this.startOnPlay) {
this.setPlaybackRate(playbackRate)
this.setVolume(volume)
onStart()
this.startOnPlay = false
Expand Down
3 changes: 3 additions & 0 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export default class FilePlayer extends Base {
setVolume (fraction) {
this.player.volume = fraction
}
setPlaybackRate (rate) {
this.player.playbackRate = rate
}
getDuration () {
if (!this.isReady) return null
return this.player.duration
Expand Down
3 changes: 3 additions & 0 deletions src/players/Vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export default class Vimeo extends Base {
setVolume (fraction) {
this.postMessage('setVolume', fraction)
}
setPlaybackRate (rate) {
this.postMessage('setPlaybackRate', rate)
}
getDuration () {
return this.duration
}
Expand Down
4 changes: 4 additions & 0 deletions src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export default class YouTube extends Base {
if (!this.isReady || !this.player.setVolume) return
this.player.setVolume(fraction * 100)
}
setPlaybackRate (rate) {
if (!this.isReady || !this.player.setPlaybackRate) return
this.player.setPlaybackRate(rate)
}
getDuration () {
if (!this.isReady || !this.player.getDuration) return null
return this.player.getDuration()
Expand Down
2 changes: 2 additions & 0 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const propTypes = {
loop: bool,
controls: bool,
volume: number,
playbackRate: number,
width: oneOfType([ string, number ]),
height: oneOfType([ string, number ]),
hidden: bool,
Expand Down Expand Up @@ -45,6 +46,7 @@ export const defaultProps = {
loop: false,
controls: false,
volume: 0.8,
playbackRate: 1.0,
width: 640,
height: 360,
hidden: false,
Expand Down