Skip to content

Commit

Permalink
Add simple Duration component to improve demo
Browse files Browse the repository at this point in the history
In place of #30
  • Loading branch information
cookpete committed Jan 21, 2016
1 parent 6ed327d commit d42c6d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import './App.scss'
import './Range.scss'

import ReactPlayer from '../ReactPlayer'
import Duration from './Duration'

export default class App extends Component {
state = {
url: null,
playing: true,
volume: 0.8,
played: 0,
loaded: 0
loaded: 0,
duration: 0
};
load = url => {
this.setState({
Expand Down Expand Up @@ -204,7 +206,15 @@ export default class App extends Component {
</tr>
<tr>
<th>duration</th>
<td>{ this.state.duration }</td>
<td><Duration seconds={duration} /></td>
</tr>
<tr>
<th>elapsed</th>
<td><Duration seconds={duration * played} /></td>
</tr>
<tr>
<th>remaining</th>
<td><Duration seconds={duration * (1 - played)} /></td>
</tr>
</tbody></table>
</section>
Expand Down
24 changes: 24 additions & 0 deletions src/demo/Duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'

export default function Duration ({ className, seconds }) {
return (
<time dateTime={`P${Math.round(seconds)}S`} className={className}>
{ format(seconds) }
</time>
)
}

function format (seconds) {
const date = new Date(seconds * 1000)
const hh = date.getHours()
const mm = date.getMinutes()
const ss = pad(date.getSeconds())
if (hh) {
return `${hh}:${pad(mm)}:${ss}`
}
return `${mm}:${ss}`
}

function pad (string) {
return ('0' + string).slice(-2)
}

0 comments on commit d42c6d3

Please sign in to comment.