Skip to content

Commit

Permalink
Add audio files for the metronome
Browse files Browse the repository at this point in the history
  • Loading branch information
madzzie committed Oct 14, 2018
1 parent 3e11e96 commit ef2c9c6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Metronome.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, {Component} from 'react';
import './Metronome.css';
import click1 from './click1.wav';
import click2 from './click2.wav';

class Metronome extends Component {
state;

constructor(props) {
super(props);

Expand All @@ -12,13 +15,22 @@ class Metronome extends Component {
bpm: 100,
beatsPerMeasure: 4
};

// Create Audio objects with the files Webpack loaded,
// and we'll play them later.
this.click1 = new Audio(click1);
this.click2 = new Audio(click2);
}

handleBpmChange = event => {
const bpm = event.target.value;
this.setState({bpm});
};

startStop = () => {
this.click1.play();
};

render() {
const {playing, bpm} = this.state;

Expand All @@ -33,7 +45,8 @@ class Metronome extends Component {
value={bpm}
onChange={this.handleBpmChange}/>
</div>
<button>
{/* Add the onClick handler: */}
<button onClick={this.startStop}>
{playing ? 'Stop' : 'Start'}
</button>
</div>
Expand Down
Binary file added src/click1.wav
Binary file not shown.
Binary file added src/click2.wav
Binary file not shown.

0 comments on commit ef2c9c6

Please sign in to comment.