Skip to content

Commit ae7252b

Browse files
committed
feat!: enable dynamic play speed and add 0.1s interval option
1 parent bc6a72d commit ae7252b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/App.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,14 @@ class App extends React.Component {
365365

366366
handleSpeedChange = (event) => {
367367
const newSpeed = parseInt(event.target.value);
368-
this.setState({ playSpeed: newSpeed });
368+
this.setState({ playSpeed: newSpeed }, () => {
369+
if (this.state.isPlaying) {
370+
clearInterval(this.timerID);
371+
this.timerID = setInterval(() => {
372+
this.handleNextEvent();
373+
}, newSpeed);
374+
}
375+
});
369376
};
370377

371378
handleKeyPress = (event) => {
@@ -1077,11 +1084,8 @@ class App extends React.Component {
10771084
</div>
10781085
<div>
10791086
<button onClick={this.handlePlayStop}>{this.state.isPlaying ? "Stop" : "Play"}</button>
1080-
<select
1081-
value={this.state.playSpeed}
1082-
onChange={this.handleSpeedChange}
1083-
disabled={this.state.isPlaying}
1084-
>
1087+
<select value={this.state.playSpeed} onChange={this.handleSpeedChange}>
1088+
<option value="100">0.1s</option>
10851089
<option value="250">0.25s</option>
10861090
<option value="500">0.5s</option>
10871091
<option value="1000">1s</option>

0 commit comments

Comments
 (0)