Edita código
Copiar al portapapeles
Ejecutar »
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>GalerÃa de Efectos Sonoros - Con Controles y Visualización</title> <style> :root { --color1: #6a11cb; --color2: #2575fc; } body { font-family: Arial, sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background: linear-gradient(to right, var(--color1), var(--color2)); animation: backgroundChange 30s infinite; transition: background 2s ease; } @keyframes backgroundChange { 0%, 100% { background: linear-gradient(to right, var(--color1), var(--color2)); } 50% { background: linear-gradient(to right, var(--color2), var(--color1)); } } .galeria { background: white; border-radius: 10px; padding: 20px; box-shadow: 0 0 15px rgba(0,0,0,0.2); text-align: center; width: 80%; max-width: 600px; } .control { display: inline-flex; align-items: center; justify-content: center; margin: 5px; padding: 10px; font-size: 40px; background: white; color: #ff6a5f; border: none; border-radius: 50%; cursor: pointer; transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease; } .control img { width: 30px; height: 30px; } .control:hover { background: #ff6a5f; color: white; box-shadow: 0 0 15px rgba(0,0,0,0.3); } .control:active { transform: scale(0.95); } .control.play-pause { background: #2575fc; color: yellow; } .control.previous-next { background: #76b852; color: white; } .control.first-last { background: #ff7e5f; color: white; } .control.loop { background: #d17eff; color: white; position: relative; } .control.loop.active { background: #8e44ad; color: yellow; } #progresoContainer { width: 100%; background-color: #ddd; margin-top: 10px; border-radius: 5px; overflow: hidden; position: relative; cursor: pointer; } #barraProgreso { width: 0; height: 20px; background: linear-gradient(to right, #76b852, #8dc26f); transition: width 0.1s ease; } #tiempoInfo { margin-top: 10px; color: #333; font-weight: bold; } .waveform-container { margin-top: 20px; height: 100px; display: flex; align-items: flex-end; background: #f0f0f0; border-radius: 5px; overflow: hidden; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1); } .waveform-bar { flex: 1; background: linear-gradient(to top, #2575fc, #6a11cb); transition: height 0.1s ease; margin: 0 1px; border-radius: 2px 2px 0 0; min-height: 5px; } #audioIndicator { margin-top: 10px; font-size: 18px; color: white; background: linear-gradient(to right, #6a11cb, #2575fc); padding: 5px 10px; border-radius: 5px; display: inline-block; line-height: 1.5; } .control-container { display: flex; justify-content: space-between; align-items: center; margin: 20px 0; } .audio-info { font-size: 14px; color: #666; margin-top: 5px; } .speed-control { display: flex; justify-content: center; align-items: center; margin-top: 10px; } .speed-control button { margin: 0 10px; padding: 10px; font-size: 20px; background: #2575fc; color: white; border: none; border-radius: 5px; cursor: pointer; transition: background 0.3s ease; } .speed-control button:hover { background: #1b5fc6; } .speed-control span { font-size: 20px; color: #333; } #volumeLabel { margin-left: 20px; font-size: 20px; color: #333; } #volumeControl { margin-left: 10px; width: 300px; } </style> </head> <body style="overflow: hidden"> <div class="galeria"> <h2 id="titulo">GalerÃa de Efectos Sonoros</h2> <div id="fileInfo" class="audio-info"></div> <div class="control-container"> <button class="control first-last" onclick="irPrimerAudio()"> <img src="img/first_page.png" alt="First Page"> </button> <button class="control previous-next" onclick="cambiarAudio(-1)"> <img src="img/skip_previous.png" alt="Previous"> </button> <button class="control play-pause" onclick="pausarReanudar()" id="playPauseButton"> <img src="img/play.png" alt="Play" id="playPauseIcon"> </button> <button class="control previous-next" onclick="cambiarAudio(1)"> <img src="img/skip_next.png" alt="Next"> </button> <button class="control first-last" onclick="irUltimoAudio()"> <img src="img/last_page.png" alt="Last Page"> </button> <button class="control loop" onclick="toggleLoop()" id="loopButton"> <img src="img/loop.png" alt="Loop" id="loopIcon"> </button> </div> <div id="progresoContainer"> <div id="barraProgreso"></div> </div> <div id="tiempoInfo">0:00 / 0:00</div> <div id="audioIndicator">1 / 3</div> <div class="waveform-container" id="waveform"></div> <div class="speed-control"> <button onclick="adjustSpeed(-0.1)">-</button> <span id="speedDisplay">1.0x</span> <button onclick="adjustSpeed(0.1)">+</button> <span id="volumeLabel">🔊</span> <!-- Distintivo de volumen --> <input type="range" id="volumeControl" min="0" max="1" step="0.01" value="1" onchange="adjustVolume(this.value)"> </div> <audio id="audioPlayer"></audio> </div> <script> const audioFiles = [ { src: "audios/un-ano-mas.m4a", title: "Un año más" }, { src: "audios/a-cantaros.mp3", title: "A cántaros" }, { src: "audios/romance-rosabella-y-domingo.mp3", title: "Romance de Rosabella y Domingo" } ]; let currentAudioIndex = 0; let isPlaying = false; let currentPlaybackRate = 1.0; // Variable para la velocidad de reproducción const audioPlayer = document.getElementById('audioPlayer'); const playPauseButton = document.getElementById('playPauseButton'); const playPauseIcon = document.getElementById('playPauseIcon'); const loopButton = document.getElementById('loopButton'); const progresoContainer = document.getElementById('progresoContainer'); const barraProgreso = document.getElementById('barraProgreso'); const tiempoInfo = document.getElementById('tiempoInfo'); const audioIndicator = document.getElementById('audioIndicator'); const fileInfo = document.getElementById('fileInfo'); const speedDisplay = document.getElementById('speedDisplay'); const waveformContainer = document.getElementById('waveform'); audioPlayer.addEventListener('loadedmetadata', actualizarDuracion); audioPlayer.addEventListener('timeupdate', actualizarProgreso); audioPlayer.addEventListener('ended', handleAudioEnd); progresoContainer.addEventListener('click', seek); function cargarAudio(index) { const audio = audioFiles[index]; audioPlayer.src = audio.src; fileInfo.textContent = audio.title; audioIndicator.textContent = `${index + 1} / ${audioFiles.length}`; playPauseIcon.src = "img/play.png"; resetWaveform(); audioPlayer.playbackRate = currentPlaybackRate; // <-- Añade esta lÃnea } function pausarReanudar() { if (!isPlaying) { audioPlayer.play(); audioPlayer.playbackRate = currentPlaybackRate; // Aplica la velocidad guardada playPauseIcon.src = "img/pause.png"; isPlaying = true; } else { audioPlayer.pause(); playPauseIcon.src = "img/play.png"; isPlaying = false; resetWaveform(); } } function toggleLoop() { loopButton.classList.toggle('active'); } function actualizarProgreso() { const porcentaje = (audioPlayer.currentTime / audioPlayer.duration) * 100; barraProgreso.style.width = porcentaje + '%'; tiempoInfo.textContent = `${formatearTiempo(audioPlayer.currentTime)} / ${formatearTiempo(audioPlayer.duration)}`; if (isPlaying) { actualizarFormaDeOnda(); } } function actualizarDuracion() { tiempoInfo.textContent = `0:00 / ${formatearTiempo(audioPlayer.duration)}`; } function formatearTiempo(segundos) { const minutos = Math.floor(segundos / 60); const seg = Math.floor(segundos % 60); return `${minutos}:${seg < 10 ? '0' : ''}${seg}`; } function cambiarAudio(direccion) { currentAudioIndex += direccion; if (currentAudioIndex < 0) { currentAudioIndex = audioFiles.length - 1; } else if (currentAudioIndex >= audioFiles.length) { currentAudioIndex = 0; } cargarAudio(currentAudioIndex); if (isPlaying) { audioPlayer.play(); playPauseIcon.src = "img/pause.png"; } } function irPrimerAudio() { currentAudioIndex = 0; cargarAudio(currentAudioIndex); if (isPlaying) { audioPlayer.play(); playPauseIcon.src = "img/pause.png"; } } function irUltimoAudio() { currentAudioIndex = audioFiles.length - 1; cargarAudio(currentAudioIndex); if (isPlaying) { audioPlayer.play(); playPauseIcon.src = "img/pause.png"; } } function seek(event) { const clickX = event.offsetX; const width = progresoContainer.clientWidth; const duration = audioPlayer.duration; audioPlayer.currentTime = (clickX / width) * duration; } function adjustSpeed(change) { currentPlaybackRate = Math.max(0.1, Math.min(4.0, audioPlayer.playbackRate + change)); audioPlayer.playbackRate = currentPlaybackRate; // Actualiza la velocidad speedDisplay.textContent = `${currentPlaybackRate.toFixed(1)}x`; } function generarFormaDeOnda() { waveformContainer.innerHTML = ''; const barCount = 50; for (let i = 0; i < barCount; i++) { const bar = document.createElement('div'); bar.className = 'waveform-bar'; bar.style.height = '5px'; waveformContainer.appendChild(bar); } } function actualizarFormaDeOnda() { const bars = waveformContainer.children; for (let i = 0; i < bars.length; i++) { bars[i].style.height = `${Math.random() * 100}%`; } } function resetWaveform() { const bars = waveformContainer.children; for (let i = 0; i < bars.length; i++) { bars[i].style.height = '5px'; } } function handleAudioEnd() { if (loopButton.classList.contains('active')) { currentAudioIndex = (currentAudioIndex + 1) % audioFiles.length; cargarAudio(currentAudioIndex); audioPlayer.play(); } else { if (currentAudioIndex < audioFiles.length - 1) { currentAudioIndex++; cargarAudio(currentAudioIndex); audioPlayer.play(); } else { isPlaying = false; playPauseIcon.src = "img/play.png"; resetWaveform(); } } } function adjustVolume(volume) { audioPlayer.volume = volume; } document.getElementById('volumeControl').value = audioPlayer.volume; cargarAudio(currentAudioIndex); generarFormaDeOnda(); resetWaveform(); </script> </body> </html>
Resultado