Skip to content

Commit

Permalink
Tidy up getSecondsLoaded
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Apr 21, 2018
1 parent d549cef commit 93351f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ Use [`ref`](https://facebook.github.io/react/docs/refs-and-the-dom.html) to call
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
`getCurrentTime()` | Returns the number of seconds that have been played<br />&nbsp;&nbsp;Returns `null` if unavailable
`getSecondsLoaded()` | Returns the number of seconds that have been loaded<br />&nbsp;&nbsp;Returns `null` if unavailable or unsupported
`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<br />&nbsp;&nbsp;Returns `null` if the internal player is unavailable

Expand Down
10 changes: 4 additions & 6 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ export default class ReactPlayer extends Component {
componentWillUpdate (nextProps) {
this.config = getConfig(nextProps, defaultProps)
}

getSecondsLoaded = () => {
if (!this.player) return null
return this.player.getSecondsLoaded()
}

getDuration = () => {
if (!this.player) return null
return this.player.getDuration()
Expand All @@ -56,6 +50,10 @@ export default class ReactPlayer extends Component {
if (!this.player) return null
return this.player.getCurrentTime()
}
getSecondsLoaded = () => {
if (!this.player) return null
return this.player.getSecondsLoaded()
}
getInternalPlayer = (key = 'player') => {
if (!this.player) return null
return this.player.getInternalPlayer(key)
Expand Down
18 changes: 7 additions & 11 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,18 @@ export class FilePlayer extends Component {
getCurrentTime () {
return this.player.currentTime
}
// This methodology was take from video.js
getBufferedEnd () {
const buffered = this.player.buffered
getSecondsLoaded () {
const { buffered } = this.player
if (buffered.length === 0) {
return 0
}
const end = buffered.end(buffered.length - 1)
const duration = this.getDuration()
let end = buffered.end(buffered.length - 1)

if (end > duration) {
end = duration
return duration
}

return end
}
getSecondsLoaded () {
if (this.player.buffered.length === 0) return 0
return this.getBufferedEnd()
}
getSource (url) {
const useHLS = this.shouldUseHLS(url)
const useDASH = this.shouldUseDASH(url)
Expand Down
4 changes: 4 additions & 0 deletions src/singlePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export default function createSinglePlayer (activePlayer) {
if (!this.player) return null
return this.player.getCurrentTime()
}
getSecondsLoaded = () => {
if (!this.player) return null
return this.player.getSecondsLoaded()
}
getInternalPlayer = (key = 'player') => {
if (!this.player) return null
return this.player.getInternalPlayer(key)
Expand Down

0 comments on commit 93351f9

Please sign in to comment.