質問するログイン新規登録

質問編集履歴

1

コード

2020/09/05 00:10

投稿

TofuLove
TofuLove

スコア14

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  オーディオの読み込みが終わると押せるようになる再生ボタンを押すと、音楽が流れるものを制作しています。
4
4
  下記はデモです。
5
- [デモ(CodeSandBox)](https://codesandbox.io/s/suspicious-dijkstra-eojk1?fontsize=14&hidenavigation=1&theme=dark)
5
+ [デモ(CodeSandBox)](https://codesandbox.io/s/cool-microservice-e8vto?fontsize=14&hidenavigation=1&theme=dark)
6
6
  音楽ファイルを読み込むと、音楽の総再生時間を表示します。
7
7
 
8
8
  デモは下記を使用しています。
@@ -59,15 +59,18 @@
59
59
  return;
60
60
  }
61
61
  sampleSource.disconnect();
62
+ setCurrent(0);
62
63
  setPlaying(false);
63
64
  };
64
65
 
65
66
  const changeSeek = (e) => {
67
+ setCurrent(e.target.value);
68
+ audioCtx.currentTime = current;
66
- console.log(audioCtx.getOutputTimestamp());
69
+ console.log(audioCtx.currentTime);
67
70
  };
68
71
 
69
72
  return (
70
- <div>
73
+ <>
71
74
  <p>曲の長さ {total}</p>
72
75
  <p>現在再生時間 {current}</p>
73
76
  <button onClick={playAudio} disabled={loaded ? false : true}>
@@ -75,14 +78,18 @@
75
78
  </button>
76
79
  <input
77
80
  onChange={changeSeek}
78
- defaultValue={0}
81
+ value={current}
79
82
  type="range"
80
83
  max={total}
81
84
  style={inputStyle}
82
85
  />
83
- </div>
86
+ </>
84
87
  );
85
88
  };
89
+
90
+ const inputStyle = {
91
+ width: "100%"
92
+ };
86
93
  ```
87
94
 
88
95
  ### 試したこと