Skip to content

Commit 9a2ae22

Browse files
committed
Add controls prop
Now that SoundCloud uses filePlayer we can have a generic `controls` prop The only quirk is that Vimeo controls are not configurable and will always display Serves as a better solution for #59 and #11
1 parent 5393343 commit 9a2ae22

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Prop | Description | Default
7777
`url` | The url of a video or song to play
7878
`playing` | Set to `true` or `false` to pause or play the media | `false`
7979
`loop` | Set to `true` or `false` to loop the media | `false`
80+
`controls` | Set to `true` or `false` to display native player controls<br />*Note: Vimeo player controls are not configurable and will always display* | `false`
8081
`volume` | Sets the volume of the appropriate player | `0.8`
8182
`width` | Sets the width of the player | `640`
8283
`height` | Sets the height of the player | `360`
@@ -85,11 +86,11 @@ Prop | Description | Default
8586

8687
#### Callback props
8788

88-
Callback props take a function that gets fired on various player events
89+
Callback props take a function that gets fired on various player events:
8990

9091
Prop | Description
9192
---- | -----------
92-
`onProgress` | Callback containing `played` and `loaded` progress as a fraction<br/>eg `{ played: 0.12, loaded: 0.34 }`
93+
`onProgress` | Callback containing `played` and `loaded` progress as a fraction<br />eg `{ played: 0.12, loaded: 0.34 }`
9394
`onDuration` | Callback containing duration of the media, in seconds
9495
`onStart` | Called when media starts playing
9596
`onPlay` | Called when media starts or resumes playing after pausing or buffering
@@ -100,14 +101,14 @@ Prop | Description
100101

101102
#### Config props
102103

103-
These props allow you to override the parameters for the various players
104+
These props allow you to override the parameters for the various players:
104105

105106
Prop | Description
106107
---- | -----------
107-
`soundcloudConfig` | Configuration object for the SoundCloud player. Set `clientId` to your own SoundCloud app [client ID](https://soundcloud.com/you/apps)
108-
`vimeoConfig` | Configuration object for the Vimeo player. Set `iframeParams` to override the [default params](https://developer.vimeo.com/player/embedding#universal-parameters). Set `preload` for [preloading](#preloading)
109-
`youtubeConfig` | Configuration object for the YouTube player. Set `playerVars` to override the [default player vars](https://developers.google.com/youtube/player_parameters?playerVersion=HTML5). Set `preload` for [preloading](#preloading)
110-
`fileConfig` | Configuration object for the file player. Set `attributes` to apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes)
108+
`soundcloudConfig` | Configuration object for the SoundCloud player.<br />Set `clientId` to your own SoundCloud app [client ID](https://soundcloud.com/you/apps).
109+
`vimeoConfig` | Configuration object for the Vimeo player.<br />Set `iframeParams` to override the [default params](https://developer.vimeo.com/player/embedding#universal-parameters).<br />Set `preload` for [preloading](#preloading).
110+
`youtubeConfig` | Configuration object for the YouTube player.<br />Set `playerVars` to override the [default player vars](https://developers.google.com/youtube/player_parameters?playerVersion=HTML5).<br />Set `preload` for [preloading](#preloading).
111+
`fileConfig` | Configuration object for the file player.<br />Set `attributes` to apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes).
111112

112113
##### Preloading
113114

src/players/FilePlayer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,21 @@ export default class FilePlayer extends Base {
5252
return this.player.buffered.end(0) / this.getDuration()
5353
}
5454
render () {
55+
const { controls, fileConfig } = this.props
5556
const Media = AUDIO_EXTENSIONS.test(this.props.url) ? 'audio' : 'video'
56-
const attributes = this.props.fileConfig.attributes
5757
const style = {
5858
width: '100%',
5959
height: '100%',
6060
display: this.props.url ? 'block' : 'none'
6161
}
62-
return <Media ref='player' style={style} preload='auto' {...attributes} />
62+
return (
63+
<Media
64+
ref='player'
65+
style={style}
66+
preload='auto'
67+
controls={controls}
68+
{...fileConfig.attributes}
69+
/>
70+
)
6371
}
6472
}

src/players/SoundCloud.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export default class SoundCloud extends FilePlayer {
5454
}, this.props.onError)
5555
}
5656
render () {
57+
const { url, controls } = this.props
5758
const style = {
58-
display: this.props.url ? 'block' : 'none',
59+
display: url ? 'block' : 'none',
5960
height: '100%',
6061
backgroundImage: this.state.image ? 'url(' + this.state.image + ')' : null,
6162
backgroundSize: 'cover',
@@ -68,6 +69,7 @@ export default class SoundCloud extends FilePlayer {
6869
type='audio/mpeg'
6970
preload='auto'
7071
style={{ width: '100%', height: '100%' }}
72+
controls={controls}
7173
/>
7274
</div>
7375
)

src/players/YouTube.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const PLAYER_ID = 'youtube-player'
1212
const BLANK_VIDEO_URL = 'https://www.youtube.com/watch?v=GlCmAC4MHek'
1313
const DEFAULT_PLAYER_VARS = {
1414
autoplay: 0,
15-
controls: 0,
1615
playsinline: 1,
1716
showinfo: 0,
1817
rel: 0,
@@ -70,6 +69,7 @@ export default class YouTube extends Base {
7069
videoId: id,
7170
playerVars: {
7271
...DEFAULT_PLAYER_VARS,
72+
controls: this.props.controls ? 1 : 0,
7373
...this.props.youtubeConfig.playerVars,
7474
start: parseStartTime(url),
7575
origin: window.location.origin

src/props.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const propTypes = {
44
url: PropTypes.string,
55
playing: PropTypes.bool,
66
loop: PropTypes.bool,
7+
controls: PropTypes.bool,
78
volume: PropTypes.number,
89
width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
910
height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
@@ -36,6 +37,7 @@ export const propTypes = {
3637
export const defaultProps = {
3738
playing: false,
3839
loop: false,
40+
controls: false,
3941
volume: 0.8,
4042
width: 640,
4143
height: 360,

0 commit comments

Comments
 (0)