File size: 15,491 Bytes
ddace5e
 
 
 
 
e61a60b
ddace5e
 
 
 
 
 
 
e61a60b
 
 
ddace5e
e61a60b
ddace5e
 
 
 
e61a60b
 
 
ddace5e
e61a60b
 
ddace5e
e61a60b
 
 
 
 
 
 
ddace5e
e61a60b
73384c6
e61a60b
 
 
73384c6
e61a60b
73384c6
 
e61a60b
 
73384c6
e61a60b
 
 
 
 
 
ddace5e
e61a60b
 
 
 
 
73384c6
ddace5e
e61a60b
 
ddace5e
73384c6
e61a60b
ddace5e
e61a60b
 
 
73384c6
ddace5e
e61a60b
 
 
73384c6
e61a60b
 
 
73384c6
ddace5e
e61a60b
ddace5e
 
e61a60b
 
ddace5e
 
 
 
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
73384c6
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73384c6
e61a60b
 
 
73384c6
e61a60b
73384c6
 
 
 
e61a60b
73384c6
e61a60b
 
73384c6
e61a60b
 
73384c6
 
e61a60b
ddace5e
e61a60b
ddace5e
e61a60b
73384c6
e61a60b
73384c6
ddace5e
 
 
 
e61a60b
 
ddace5e
e61a60b
 
 
 
 
73384c6
 
ddace5e
e61a60b
 
 
 
 
ddace5e
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddace5e
 
73384c6
 
 
e61a60b
 
 
 
 
 
ddace5e
e61a60b
 
 
 
ddace5e
e61a60b
 
 
 
73384c6
e61a60b
 
 
 
73384c6
e61a60b
 
 
 
ddace5e
 
e61a60b
 
 
 
 
 
 
 
ddace5e
73384c6
ddace5e
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
 
ddace5e
e61a60b
 
 
 
 
ddace5e
e61a60b
 
ddace5e
e61a60b
 
 
ddace5e
e61a60b
 
 
 
 
 
73384c6
ddace5e
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
ddace5e
 
e61a60b
 
 
ddace5e
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddace5e
 
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
ddace5e
 
e61a60b
 
 
 
ddace5e
 
e61a60b
 
 
 
73384c6
e61a60b
 
 
 
 
 
 
 
 
 
 
 
ddace5e
e61a60b
 
 
 
 
 
 
 
 
 
 
 
 
73384c6
 
 
e61a60b
 
ddace5e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>音声動画プレイヤー</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #0a192f;
            color: #e6f1ff;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        h1 {
            color: #64ffda;
            text-align: center;
            margin-bottom: 30px;
            border-bottom: 1px solid #64ffda;
            padding-bottom: 10px;
            width: 100%;
        }
        
        .container {
            display: flex;
            flex-direction: column;
            width: 100%;
            max-width: 800px;
            background-color: #112240;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 0 20px rgba(100, 255, 218, 0.2);
        }
        
        .video-container {
            position: relative;
            width: 100%;
            margin-bottom: 20px;
        }
        
        video {
            width: 100%;
            border-radius: 5px;
            background-color: #000;
        }
        
        .controls {
            display: flex;
            flex-direction: column;
            gap: 15px;
            margin-bottom: 20px;
        }
        
        .audio-controls {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin-bottom: 15px;
        }
        
        .audio-item {
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .audio-item label {
            min-width: 50px;
            color: #64ffda;
        }
        
        input[type="range"] {
            flex-grow: 1;
            height: 8px;
            -webkit-appearance: none;
            background: #1e2a47;
            border-radius: 5px;
            outline: none;
        }
        
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 18px;
            height: 18px;
            background: #64ffda;
            border-radius: 50%;
            cursor: pointer;
        }
        
        .settings {
            background-color: #1e2a47;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 20px;
        }
        
        .setting-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        
        .setting-item:last-child {
            margin-bottom: 0;
        }
        
        .setting-item label {
            color: #ccd6f6;
        }
        
        input[type="number"], input[type="checkbox"], select {
            background-color: #112240;
            border: 1px solid #64ffda;
            color: #e6f1ff;
            padding: 5px;
            border-radius: 3px;
        }
        
        button {
            background-color: #0a192f;
            color: #64ffda;
            border: 1px solid #64ffda;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-weight: bold;
            transition: all 0.3s;
        }
        
        button:hover {
            background-color: #64ffda;
            color: #0a192f;
        }
        
        .buttons {
            display: flex;
            gap: 10px;
            justify-content: center;
        }
        
        .tech-decoration {
            width: 100%;
            height: 2px;
            background: linear-gradient(90deg, transparent, #64ffda, transparent);
            margin: 20px 0;
        }
    </style>
</head>
<body>
    <h1>音声動画プレイヤー</h1>
    
    <div class="container">
        <div class="video-container">
            <video id="video" muted>
                <source src="v.mp4" type="video/mp4">
            </video>
        </div>
        
        <div class="tech-decoration"></div>
        
        <div class="settings">
            <h2>設定</h2>
            <div class="setting-item">
                <label for="start-time">再生開始秒数:</label>
                <input type="number" id="start-time" min="0" value="0" step="0.1">
            </div>
            <div class="setting-item">
                <label for="end-time">再生終了秒数:</label>
                <input type="number" id="end-time" min="0" value="0" step="0.1">
            </div>
            <div class="setting-item">
                <label for="loop">ループ再生:</label>
                <input type="checkbox" id="loop">
            </div>
            <div class="setting-item">
                <label for="playback-rate">再生速度:</label>
                <select id="playback-rate">
                    <option value="0.25">0.25x</option>
                    <option value="0.5">0.5x</option>
                    <option value="0.75">0.75x</option>
                    <option value="1" selected>1x</option>
                    <option value="1.25">1.25x</option>
                    <option value="1.5">1.5x</option>
                    <option value="2">2x</option>
                    <option value="3">3x</option>
                </select>
            </div>
            <div class="setting-item">
                <label for="global-volume">全体音量係数:</label>
                <input type="range" id="global-volume" min="0" max="3" step="0.1" value="1">
                <span id="global-volume-value">1</span>
            </div>
        </div>
        
        <div class="tech-decoration"></div>
        
        <div class="audio-controls">
            <h2>音声コントロール</h2>
            <div class="audio-item">
                <label>p.mp3</label>
                <input type="range" class="volume-slider" data-audio="p" min="0" max="1" step="0.01" value="1">
                <span class="volume-value">1</span>
            </div>
            <div class="audio-item">
                <label>a.mp3</label>
                <input type="range" class="volume-slider" data-audio="a" min="0" max="1" step="0.01" value="1">
                <span class="volume-value">1</span>
            </div>
            <div class="audio-item">
                <label>t.mp3</label>
                <input type="range" class="volume-slider" data-audio="t" min="0" max="1" step="0.01" value="1">
                <span class="volume-value">1</span>
            </div>
            <div class="audio-item">
                <label>s.mp3</label>
                <input type="range" class="volume-slider" data-audio="s" min="0" max="1" step="0.01" value="1">
                <span class="volume-value">1</span>
            </div>
            <div class="audio-item">
                <label>k.mp3</label>
                <input type="range" class="volume-slider" data-audio="k" min="0" max="1" step="0.01" value="1">
                <span class="volume-value">1</span>
            </div>
        </div>
        
        <div class="tech-decoration"></div>
        
        <div class="buttons">
            <button id="play-btn">再生</button>
            <button id="pause-btn">一時停止</button>
            <button id="stop-btn">停止</button>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 要素を取得
            const video = document.getElementById('video');
            const playBtn = document.getElementById('play-btn');
            const pauseBtn = document.getElementById('pause-btn');
            const stopBtn = document.getElementById('stop-btn');
            const startTimeInput = document.getElementById('start-time');
            const endTimeInput = document.getElementById('end-time');
            const loopCheckbox = document.getElementById('loop');
            const playbackRateSelect = document.getElementById('playback-rate');
            const globalVolumeSlider = document.getElementById('global-volume');
            const globalVolumeValue = document.getElementById('global-volume-value');
            const volumeSliders = document.querySelectorAll('.volume-slider');
            const volumeValues = document.querySelectorAll('.volume-value');
            
            // 音声オブジェクトを作成
            const audioContext = new (window.AudioContext || window.webkitAudioContext)();
            const audioBuffers = {};
            const audioSources = {};
            const gainNodes = {};
            
            // 音声ファイル名の配列
            const audioFiles = ['p', 'a', 't', 's', 'k'];
            
            // 初期化
            let videoDuration = 0;
            let isPlaying = false;
            
            // 動画のメタデータが読み込まれたら
            video.addEventListener('loadedmetadata', function() {
                videoDuration = video.duration;
                endTimeInput.value = videoDuration.toFixed(1);
                endTimeInput.max = videoDuration;
                startTimeInput.max = videoDuration - 0.1;
            });
            
            // 音声ファイルを読み込む
            function loadAudioFiles() {
                audioFiles.forEach(file => {
                    fetch(`${file}.mp3`)
                        .then(response => response.arrayBuffer())
                        .then(arrayBuffer => audioContext.decodeAudioData(arrayBuffer))
                        .then(audioBuffer => {
                            audioBuffers[file] = audioBuffer;
                            gainNodes[file] = audioContext.createGain();
                            gainNodes[file].gain.value = 1;
                        })
                        .catch(error => console.error(`Error loading ${file}.mp3:`, error));
                });
            }
            
            // 再生関数
            function playMedia() {
                if (isPlaying) return;
                
                const startTime = parseFloat(startTimeInput.value) || 0;
                let endTime = parseFloat(endTimeInput.value) || videoDuration;
                const loop = loopCheckbox.checked;
                const playbackRate = parseFloat(playbackRateSelect.value);
                const globalVolume = parseFloat(globalVolumeSlider.value);
                
                // 終了時間が動画の長さを超えないように
                endTime = Math.min(endTime, videoDuration);
                
                // 動画を設定
                video.currentTime = startTime;
                video.playbackRate = playbackRate;
                video.muted = true;
                
                // 音声を再生
                audioFiles.forEach(file => {
                    if (audioBuffers[file]) {
                        // 既存のソースがあれば停止
                        if (audioSources[file]) {
                            audioSources[file].stop();
                        }
                        
                        const source = audioContext.createBufferSource();
                        source.buffer = audioBuffers[file];
                        
                        // ボリュームスライダーの値を取得
                        const volumeSlider = document.querySelector(`.volume-slider[data-audio="${file}"]`);
                        const volume = parseFloat(volumeSlider.value) * globalVolume;
                        
                        // ゲインノードを設定
                        gainNodes[file].gain.value = volume;
                        
                        // 接続
                        source.connect(gainNodes[file]);
                        gainNodes[file].connect(audioContext.destination);
                        
                        // 再生
                        source.start(0, startTime, endTime - startTime);
                        
                        // ループ設定
                        source.loop = loop;
                        if (loop) {
                            source.loopStart = startTime;
                            source.loopEnd = endTime;
                        }
                        
                        audioSources[file] = source;
                    }
                });
                
                // 動画を再生
                video.play();
                isPlaying = true;
                
                // 終了時間に達したら停止
                video.ontimeupdate = function() {
                    if (video.currentTime >= endTime) {
                        if (!loop) {
                            stopMedia();
                        } else {
                            video.currentTime = startTime;
                        }
                    }
                };
            }
            
            // 一時停止関数
            function pauseMedia() {
                if (!isPlaying) return;
                
                video.pause();
                audioFiles.forEach(file => {
                    if (audioSources[file]) {
                        audioSources[file].stop();
                        audioSources[file] = null;
                    }
                });
                
                isPlaying = false;
            }
            
            // 停止関数
            function stopMedia() {
                pauseMedia();
                video.currentTime = parseFloat(startTimeInput.value) || 0;
            }
            
            // イベントリスナーを設定
            playBtn.addEventListener('click', playMedia);
            pauseBtn.addEventListener('click', pauseMedia);
            stopBtn.addEventListener('click', stopMedia);
            
            // ボリュームスライダーのイベント
            volumeSliders.forEach((slider, index) => {
                slider.addEventListener('input', function() {
                    const value = parseFloat(this.value);
                    volumeValues[index].textContent = value.toFixed(2);
                    
                    if (isPlaying && audioSources[this.dataset.audio] && gainNodes[this.dataset.audio]) {
                        const globalVolume = parseFloat(globalVolumeSlider.value);
                        gainNodes[this.dataset.audio].gain.value = value * globalVolume;
                    }
                });
            });
            
            // 全体音量スライダーのイベント
            globalVolumeSlider.addEventListener('input', function() {
                const value = parseFloat(this.value);
                globalVolumeValue.textContent = value.toFixed(1);
                
                if (isPlaying) {
                    audioFiles.forEach(file => {
                        if (gainNodes[file]) {
                            const volumeSlider = document.querySelector(`.volume-slider[data-audio="${file}"]`);
                            const volume = parseFloat(volumeSlider.value) * value;
                            gainNodes[file].gain.value = volume;
                        }
                    });
                }
            });
            
            // 初期化
            loadAudioFiles();
        });
    </script>
</body>
</html>