Skip to content

Commit

Permalink
Add vidmeConfig with choice of video format
Browse files Browse the repository at this point in the history
  • Loading branch information
Webmaster1116 committed Apr 13, 2017
1 parent ca483f1 commit 0ddcd06
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Prop | Description
`soundcloudConfig` | Configuration object for the SoundCloud player.<br />Set `clientId` to your own SoundCloud app [client ID](https://soundcloud.com/you/apps).<br />Set `showArtwork` to `false` to not load any artwork to display.
`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).
`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).
`vidmeConfig` | Configuration object for the Vidme player.<br />Set `format` to use a certain quality of video, when available.<br />Possible values: `240p`, `480p`, `720p`, `1080p`, `dash`, `hls`
`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).

##### Preloading
Expand Down
3 changes: 2 additions & 1 deletion src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ export default class ReactPlayer extends Component {
}
renderPlayer = Player => {
const active = Player.canPlay(this.props.url)
const { youtubeConfig, soundcloudConfig, vimeoConfig, fileConfig, ...activeProps } = this.props
const { youtubeConfig, soundcloudConfig, vimeoConfig, vidmeConfig, fileConfig, ...activeProps } = this.props
const props = active ? { ...activeProps, ref: this.ref } : {}
return (
<Player
key={Player.displayName}
youtubeConfig={youtubeConfig}
soundcloudConfig={soundcloudConfig}
vimeoConfig={vimeoConfig}
vidmeConfig={vidmeConfig}
fileConfig={fileConfig}
{...props}
/>
Expand Down
14 changes: 13 additions & 1 deletion src/players/Vidme.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ export default class Vidme extends FilePlayer {
}
})
}
getURL ({ video }) {
const { vidmeConfig } = this.props
if (vidmeConfig.format && video.formats && video.formats.length !== 0) {
const index = video.formats.findIndex(f => f.type === vidmeConfig.format)
if (index !== -1) {
return video.formats[index].uri
} else {
console.warn(`Vidme format "${vidmeConfig.format}" was not found for ${video.full_url}`)
}
}
return video.complete_url
}
load (url) {
const { onError } = this.props
this.stop()
this.getData(url).then(data => {
if (!this.mounted) return
this.player.src = data.video.complete_url
this.player.src = this.getURL(data)
}, onError)
}
}
6 changes: 6 additions & 0 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const propTypes = {
iframeParams: object,
preload: bool
}),
vidmeConfig: shape({
format: string
}),
fileConfig: shape({
attributes: object
}),
Expand Down Expand Up @@ -65,6 +68,9 @@ export const defaultProps = {
iframeParams: {},
preload: false
},
vidmeConfig: {
format: null
},
fileConfig: {
attributes: {}
},
Expand Down

0 comments on commit 0ddcd06

Please sign in to comment.