Skip to content

Commit

Permalink
Add loadedSeconds and playedSeconds to onProgress
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorapple committed Apr 11, 2017
1 parent 0214754 commit c03add1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Prop | Description
`onReady` | Called when media is loaded and ready to play. If `playing` is set to `true`, media will play immediately
`onStart` | Called when media starts playing
`onPlay` | Called when media starts or resumes playing after pausing or buffering
`onProgress` | Callback containing `played` and `loaded` progress as a fraction<br />eg `{ played: 0.12, loaded: 0.34 }`
`onProgress` | Callback containing progress `played`, `loaded` (fraction), `playedSeconds` and `loadedSeconds` (seconds)<br />eg `{ played: 0.12, playedSeconds: 11.3, loaded: 0.34, loadedSeconds: 16.7 }`
`onDuration` | Callback containing duration of the media, in seconds
`onPause` | Called when media is paused
`onBuffer` | Called when media starts buffering
Expand Down
7 changes: 7 additions & 0 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ export default class ReactPlayer extends Component {
if (this.props.url && this.player) {
const loaded = this.player.getFractionLoaded() || 0
const played = this.player.getFractionPlayed() || 0
const duration = this.player.getDuration()
const progress = {}
if (loaded !== this.prevLoaded) {
progress.loaded = loaded
if (duration) {
progress.loadedSeconds = progress.loaded * duration
}
}
if (played !== this.prevPlayed) {
progress.played = played
if (duration) {
progress.playedSeconds = progress.played * duration
}
}
if (progress.loaded || progress.played) {
this.props.onProgress(progress)
Expand Down

0 comments on commit c03add1

Please sign in to comment.