aboutsummaryrefslogtreecommitdiff
path: root/src/audio.ts
blob: 350093a32d6f26e31454788d067a7d109861f26b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import * as Config from 'config'
import * as Step from 'step'

const start = new Audio('sound/start.mp3')
const stop = new Audio('sound/stop.mp3')
const endTabata = new Audio('sound/end-tabata.mp3')
const endTraining = new Audio('sound/end-training.mp3')

export function playFromStep(config: Config.Config, step: Step.Step, elapsed: number) {
  if (step.name === 'warmup' && step.remaining === config.warmup) {
    start.play()
  } else if (step.name === 'work' && step.remaining === config.work) {
    start.play()
  } else if (step.name === 'rest' && step.remaining === config.rest) {
    stop.play()
  } else if (step.name === 'prepare' && step.remaining === config.prepare && elapsed > 0) {
    endTabata.play()
  } else if (step.name === 'end' && elapsed === Config.getDuration(config)) {
    endTraining.play()
  }
}