Skip to content

Commit

Permalink
Add playsinline prop
Browse files Browse the repository at this point in the history
  • Loading branch information
albanqoku committed Feb 28, 2017
1 parent 2171e0a commit 0a0e29c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Prop | Description | Default
`className` | Pass in a `className` to set on the root element
`style` | Add [inline styles](https://facebook.github.io/react/tips/inline-styles.html) to the root element
`progressFrequency` | The time between `onProgress` callbacks, in milliseconds | `1000`
`playsinline` | Applies the `playsinline` attribute where supported | `false`

#### Callback props

Expand Down
7 changes: 5 additions & 2 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class FilePlayer extends Base {
return true
}
componentDidMount () {
const { onPause, onEnded, onError } = this.props
const { playsinline, onPause, onEnded, onError } = this.props
this.player.addEventListener('canplay', this.onReady)
this.player.addEventListener('play', this.onPlay)
this.player.addEventListener('pause', () => {
Expand All @@ -20,7 +20,10 @@ export default class FilePlayer extends Base {
})
this.player.addEventListener('ended', onEnded)
this.player.addEventListener('error', onError)
this.player.setAttribute('webkit-playsinline', '')
if (playsinline) {
this.player.setAttribute('playsinline', '')
this.player.setAttribute('webkit-playsinline', '')
}
super.componentDidMount()
}
componentWillUnmount () {
Expand Down
3 changes: 2 additions & 1 deletion src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class YouTube extends Base {
})
}
load (url) {
const { controls, youtubeConfig, onError } = this.props
const { playsinline, controls, youtubeConfig, onError } = this.props
const id = url && url.match(MATCH_URL)[1]
if (this.isReady) {
this.player.cueVideoById({
Expand All @@ -70,6 +70,7 @@ export default class YouTube extends Base {
controls: controls ? 1 : 0,
start: parseStartTime(url),
origin: window.location.origin,
playsinline: playsinline,
...youtubeConfig.playerVars
},
events: {
Expand Down
2 changes: 2 additions & 0 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const propTypes = {
className: string,
style: object,
progressFrequency: number,
playsinline: bool,
soundcloudConfig: shape({
clientId: string,
showArtwork: bool
Expand Down Expand Up @@ -51,6 +52,7 @@ export const defaultProps = {
height: 360,
hidden: false,
progressFrequency: 1000,
playsinline: false,
soundcloudConfig: {
clientId: 'e8b6f84fbcad14c301ca1355cae1dea2',
showArtwork: true
Expand Down

0 comments on commit 0a0e29c

Please sign in to comment.