Spaces:
Running
Running
Update index.html
Browse files- index.html +39 -12
index.html
CHANGED
@@ -71,12 +71,23 @@
|
|
71 |
const volumeInput = document.getElementById('volumeInput');
|
72 |
const loopCheckbox = document.getElementById('loopCheckbox');
|
73 |
|
74 |
-
// Web Audio API
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
function updatePlaybackRate(value) {
|
82 |
const speed = parseFloat(value);
|
@@ -86,12 +97,17 @@
|
|
86 |
}
|
87 |
|
88 |
function updateVolume(value) {
|
89 |
-
const volume = parseFloat(value)
|
90 |
-
volumeInput.value =
|
91 |
-
volumeRange.value =
|
92 |
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
|
97 |
['input', 'change', 'mouseup'].forEach(eventName => {
|
@@ -129,7 +145,18 @@
|
|
129 |
updatePlaybackRate(speedRange.value);
|
130 |
updateVolume(volumeRange.value);
|
131 |
video.loop = loopCheckbox.checked;
|
|
|
|
|
|
|
132 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
</script>
|
134 |
</body>
|
135 |
-
</html>
|
|
|
71 |
const volumeInput = document.getElementById('volumeInput');
|
72 |
const loopCheckbox = document.getElementById('loopCheckbox');
|
73 |
|
74 |
+
// Web Audio APIの設定
|
75 |
+
let audioContext;
|
76 |
+
let source;
|
77 |
+
let gainNode;
|
78 |
+
|
79 |
+
function setupAudio() {
|
80 |
+
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
81 |
+
source = audioContext.createMediaElementSource(video);
|
82 |
+
gainNode = audioContext.createGain();
|
83 |
+
|
84 |
+
// 音声ノードを接続
|
85 |
+
source.connect(gainNode);
|
86 |
+
gainNode.connect(audioContext.destination);
|
87 |
+
|
88 |
+
// 初期音量設定
|
89 |
+
updateVolume(volumeRange.value);
|
90 |
+
}
|
91 |
|
92 |
function updatePlaybackRate(value) {
|
93 |
const speed = parseFloat(value);
|
|
|
97 |
}
|
98 |
|
99 |
function updateVolume(value) {
|
100 |
+
const volume = parseFloat(value);
|
101 |
+
volumeInput.value = volume;
|
102 |
+
volumeRange.value = volume;
|
103 |
|
104 |
+
if (gainNode) {
|
105 |
+
// 0-300%を0-3の値に変換 (100% = 1.0)
|
106 |
+
gainNode.gain.value = volume / 100;
|
107 |
+
} else {
|
108 |
+
// Web Audio APIが初期化される前は通常の音量制御を使用
|
109 |
+
video.volume = Math.min(volume / 100, 1);
|
110 |
+
}
|
111 |
}
|
112 |
|
113 |
['input', 'change', 'mouseup'].forEach(eventName => {
|
|
|
145 |
updatePlaybackRate(speedRange.value);
|
146 |
updateVolume(volumeRange.value);
|
147 |
video.loop = loopCheckbox.checked;
|
148 |
+
|
149 |
+
// Web Audio APIをセットアップ
|
150 |
+
setupAudio();
|
151 |
});
|
152 |
+
|
153 |
+
// iOSなどの一部ブラウザではユーザー操作がないとAudioContextがサスペンドされるので、
|
154 |
+
// ユーザー操作時に再開するようにする
|
155 |
+
document.addEventListener('click', () => {
|
156 |
+
if (audioContext && audioContext.state === 'suspended') {
|
157 |
+
audioContext.resume();
|
158 |
+
}
|
159 |
+
}, { once: true });
|
160 |
</script>
|
161 |
</body>
|
162 |
+
</html>
|