.progress-container flex: 1; background: #444; height: 6px; border-radius: 5px; cursor: pointer; position: relative;
// Reset button on video end video.addEventListener('ended', () => playPauseBtn.textContent = '▶'; ); Want to see it in action? 👉 Click here to open the live CodePen (Replace with actual Pen after creating it)
// Seek on progress bar click progressContainer.addEventListener('click', (e) => const rect = progressContainer.getBoundingClientRect(); const clickX = e.clientX - rect.left; const width = rect.width; const seekTime = (clickX / width) * video.duration; video.currentTime = seekTime; );
// Playback speed speedSelect.addEventListener('change', () => video.playbackRate = parseFloat(speedSelect.value); ); youtube html5 video player codepen
body background: #0a0a0a; display: flex; justify-content: center; align-items: center; min-height: 100vh; font-family: system-ui, 'Segoe UI', sans-serif;
muteBtn.addEventListener('click', () => if (video.volume > 0) video.volume = 0; volumeSlider.value = 0; muteBtn.textContent = '🔇'; else video.volume = 1; volumeSlider.value = 1; muteBtn.textContent = '🔊';
const formatTime = (seconds) => const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return $mins:$secs < 10 ? '0' : ''$secs ; ; timeDisplay.textContent = $formatTime(video.currentTime) / $formatTime(video.duration) ; ); '🔇' : '🔊'; ); video width: 100%; display:
.controls display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 18px; background: #1e1e1e; color: white;
.player-container max-width: 900px; width: 90%; background: #000; border-radius: 20px; overflow: hidden; box-shadow: 0 20px 35px rgba(0,0,0,0.5);
);
const video = document.getElementById('myVideo'); const playPauseBtn = document.getElementById('playPauseBtn'); const progressContainer = document.querySelector('.progress-container'); const progressBar = document.getElementById('progressBar'); const timeDisplay = document.getElementById('timeDisplay'); const volumeSlider = document.getElementById('volumeSlider'); const muteBtn = document.getElementById('muteBtn'); const speedSelect = document.getElementById('speedSelect'); const fullscreenBtn = document.getElementById('fullscreenBtn'); // Play/Pause function togglePlay() if (video.paused) video.play(); playPauseBtn.textContent = '⏸'; else video.pause(); playPauseBtn.textContent = '▶';
// Volume volumeSlider.addEventListener('input', () => video.volume = volumeSlider.value; muteBtn.textContent = video.volume === 0 ? '🔇' : '🔊'; );
video width: 100%; display: block; cursor: pointer; '🔇' : '🔊'
button, select background: #333; border: none; color: white; padding: 6px 12px; border-radius: 30px; cursor: pointer; font-size: 1rem; transition: 0.2s;
.progress-bar width: 0%; height: 100%; background: #f00; border-radius: 5px;
Si continúas usando este sitio, aceptas el uso de cookies. Más información
Los ajustes de cookies en esta web están configurados para «permitir las cookies» y ofrecerte la mejor experiencia de navegación posible. Si sigues usando esta web sin cambiar tus ajustes de cookies o haces clic en «Aceptar», estarás dando tu consentimiento a esto.