Skip to content

Commit

Permalink
Fix getInternalPlayer method
Browse files Browse the repository at this point in the history
Since the refactor, the internal player is now deeper in the object tree of the various player objects
  • Loading branch information
cookpete committed Dec 12, 2017
1 parent a28d9e0 commit bbed43f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Method | Description
`seekTo(amount)` | Seek to the given number of seconds, or fraction if `amount` is between `0` and `1`
`getCurrentTime()` | Returns the number of seconds that has been played<br />&nbsp;&nbsp;Returns `null` if duration is unavailable
`getDuration()` | Returns the duration (in seconds) of the currently playing media<br />&nbsp;&nbsp;Returns `null` if duration is unavailable
`getInternalPlayer()` | Returns the internal player of whatever is currently playing<br />&nbsp;&nbsp;eg the [YouTube player instance](https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player), or the [`<video>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) element when playing a video file<br />&nbsp;&nbsp;Use `getInternalPlayer('hls')` to get the [hls.js](https://github.com/video-dev/hls.js) player<br />&nbsp;&nbsp;Use `getInternalPlayer('dash')` to get the [dash.js](https://github.com/Dash-Industry-Forum/dash.js) player
`getInternalPlayer()` | Returns the internal player of whatever is currently playing<br />&nbsp;&nbsp;eg the [YouTube player instance](https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player), or the [`<video>`](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) element when playing a video file<br />&nbsp;&nbsp;Use `getInternalPlayer('hls')` to get the [hls.js](https://github.com/video-dev/hls.js) player<br />&nbsp;&nbsp;Use `getInternalPlayer('dash')` to get the [dash.js](https://github.com/Dash-Industry-Forum/dash.js) player<br />&nbsp;&nbsp;Returns `null` if the internal player is unavailable

### Supported media

Expand Down
10 changes: 7 additions & 3 deletions src/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default class Player extends Component {
this.player.setPlaybackRate(nextProps.playbackRate)
}
}
getDuration () {
if (!this.isReady) return null
return this.player.getDuration()
}
getCurrentTime () {
if (!this.isReady) return null
return this.player.getCurrentTime()
Expand All @@ -53,9 +57,9 @@ export default class Player extends Component {
if (!this.isReady) return null
return this.player.getSecondsLoaded()
}
getDuration () {
if (!this.isReady) return null
return this.player.getDuration()
getInternalPlayer = (key) => {
if (!this.player) return null
return this.player[key]
}
seekTo (amount) {
// When seeking before player is ready, store value and seek later
Expand Down
10 changes: 5 additions & 5 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ export default class ReactPlayer extends Component {
}
return false
}
seekTo = fraction => {
if (!this.player) return null
this.player.seekTo(fraction)
}
getDuration = () => {
if (!this.player) return null
return this.player.getDuration()
Expand All @@ -51,7 +47,11 @@ export default class ReactPlayer extends Component {
}
getInternalPlayer = (key = 'player') => {
if (!this.player) return null
return this.player[key]
return this.player.getInternalPlayer(key)
}
seekTo = fraction => {
if (!this.player) return null
this.player.seekTo(fraction)
}
progress = () => {
if (this.props.url && this.player && this.player.isReady) {
Expand Down

0 comments on commit bbed43f

Please sign in to comment.