Spaces:
Running
Running
File size: 15,084 Bytes
938e951 |
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 |
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reproductor Video/Audio</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #4f46e5;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #10b981;
}
input:checked + .slider:before {
transform: translateX(26px);
}
.slider-icon {
position: absolute;
top: 50%;
transform: translateY(-50%);
color: white;
font-size: 14px;
}
.video-icon {
left: 8px;
}
.audio-icon {
right: 8px;
}
#videoContainer {
transition: all 0.3s ease;
}
#audioContainer {
transition: all 0.3s ease;
background: linear-gradient(135deg, #4f46e5 0%, #10b981 100%);
}
.progress-container {
height: 6px;
background-color: #e5e7eb;
border-radius: 3px;
cursor: pointer;
}
.progress-bar {
height: 100%;
background-color: #4f46e5;
border-radius: 3px;
width: 0%;
}
.thumbnail {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 8px;
}
.audio-visualizer {
display: flex;
align-items: flex-end;
height: 50px;
gap: 2px;
}
.audio-bar {
background-color: rgba(255, 255, 255, 0.7);
width: 4px;
border-radius: 2px;
animation: equalize 1s infinite alternate;
animation-delay: calc(var(--order) * 100ms);
}
@keyframes equalize {
0% {
height: 10%;
}
100% {
height: calc(var(--height) * 1%);
}
}
</style>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-2xl bg-white rounded-xl shadow-xl overflow-hidden">
<!-- Header -->
<div class="bg-indigo-600 p-4 text-white">
<h1 class="text-xl font-bold text-center">Reproductor Flexible</h1>
<p class="text-center text-indigo-100 text-sm">Cambia entre video y audio sin perder la reproducción</p>
</div>
<!-- Main Content -->
<div class="p-6">
<!-- Video Container (Visible by default) -->
<div id="videoContainer" class="mb-6 rounded-lg overflow-hidden relative">
<video id="mediaPlayer" class="w-full aspect-video bg-black" poster="https://i.imgur.com/3ZQZQ9m.jpg" controls>
<source id="mediaSource" src="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
Tu navegador no soporta el elemento de video.
</video>
<div id="videoOverlay" class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-30 hidden">
<button id="playBtn" class="w-16 h-16 rounded-full bg-indigo-600 text-white flex items-center justify-center hover:bg-indigo-700 transition">
<i class="fas fa-play text-2xl"></i>
</button>
</div>
</div>
<!-- Audio Container (Hidden by default) -->
<div id="audioContainer" class="hidden mb-6 rounded-lg p-6">
<div class="flex items-center">
<div class="mr-4">
<div class="w-16 h-16 rounded-lg overflow-hidden shadow-md">
<img src="https://i.imgur.com/3ZQZQ9m.jpg" alt="Thumbnail" class="thumbnail">
</div>
</div>
<div class="flex-1">
<h3 class="text-white font-medium">Big Buck Bunny</h3>
<p class="text-white text-opacity-80 text-sm">Reproduciendo en modo audio</p>
<!-- Audio Visualizer -->
<div class="audio-visualizer mt-2">
<div class="audio-bar" style="--height: 30; --order: 1;"></div>
<div class="audio-bar" style="--height: 60; --order: 2;"></div>
<div class="audio-bar" style="--height: 40; --order: 3;"></div>
<div class="audio-bar" style="--height: 80; --order: 4;"></div>
<div class="audio-bar" style="--height: 50; --order: 5;"></div>
<div class="audio-bar" style="--height: 70; --order: 6;"></div>
<div class="audio-bar" style="--height: 30; --order: 7;"></div>
<div class="audio-bar" style="--height: 90; --order: 8;"></div>
<div class="audio-bar" style="--height: 60; --order: 9;"></div>
<div class="audio-bar" style="--height: 40; --order: 10;"></div>
</div>
</div>
</div>
</div>
<!-- Custom Controls -->
<div class="space-y-4">
<!-- Progress Bar -->
<div class="progress-container" id="progressContainer">
<div class="progress-bar" id="progressBar"></div>
</div>
<!-- Time Display -->
<div class="flex justify-between text-sm text-gray-600">
<span id="currentTime">0:00</span>
<span id="duration">1:00</span>
</div>
<!-- Main Controls -->
<div class="flex items-center justify-between">
<!-- Play/Pause Button -->
<button id="playPauseBtn" class="w-12 h-12 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center hover:bg-indigo-200 transition">
<i class="fas fa-play"></i>
</button>
<!-- Volume Control -->
<div class="flex items-center space-x-2">
<i class="fas fa-volume-down text-gray-600"></i>
<input type="range" id="volumeControl" min="0" max="1" step="0.01" value="1" class="w-24">
</div>
<!-- Mode Switch -->
<div class="flex items-center space-x-3">
<span class="text-sm font-medium text-gray-700">Modo:</span>
<label class="switch">
<input type="checkbox" id="modeSwitch">
<span class="slider"></span>
<span class="slider-icon video-icon"><i class="fas fa-video"></i></span>
<span class="slider-icon audio-icon"><i class="fas fa-music"></i></span>
</label>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Elements
const mediaPlayer = document.getElementById('mediaPlayer');
const videoContainer = document.getElementById('videoContainer');
const audioContainer = document.getElementById('audioContainer');
const playPauseBtn = document.getElementById('playPauseBtn');
const playBtn = document.getElementById('playBtn');
const progressBar = document.getElementById('progressBar');
const progressContainer = document.getElementById('progressContainer');
const currentTimeDisplay = document.getElementById('currentTime');
const durationDisplay = document.getElementById('duration');
const volumeControl = document.getElementById('volumeControl');
const modeSwitch = document.getElementById('modeSwitch');
const videoOverlay = document.getElementById('videoOverlay');
// Initial state
let isVideoMode = true;
// Play/Pause functionality
function togglePlayPause() {
if (mediaPlayer.paused) {
mediaPlayer.play();
playPauseBtn.innerHTML = '<i class="fas fa-pause"></i>';
videoOverlay.classList.add('hidden');
} else {
mediaPlayer.pause();
playPauseBtn.innerHTML = '<i class="fas fa-play"></i>';
if (isVideoMode) videoOverlay.classList.remove('hidden');
}
}
playPauseBtn.addEventListener('click', togglePlayPause);
playBtn.addEventListener('click', togglePlayPause);
// Update progress bar
mediaPlayer.addEventListener('timeupdate', function() {
const progress = (mediaPlayer.currentTime / mediaPlayer.duration) * 100;
progressBar.style.width = `${progress}%`;
// Update time displays
currentTimeDisplay.textContent = formatTime(mediaPlayer.currentTime);
if (!isNaN(mediaPlayer.duration)) {
durationDisplay.textContent = formatTime(mediaPlayer.duration);
}
});
// Click on progress bar to seek
progressContainer.addEventListener('click', function(e) {
const rect = progressContainer.getBoundingClientRect();
const pos = (e.clientX - rect.left) / rect.width;
mediaPlayer.currentTime = pos * mediaPlayer.duration;
});
// Volume control
volumeControl.addEventListener('input', function() {
mediaPlayer.volume = this.value;
});
// Mode switch
modeSwitch.addEventListener('change', function() {
isVideoMode = !isVideoMode;
if (isVideoMode) {
videoContainer.classList.remove('hidden');
audioContainer.classList.add('hidden');
if (mediaPlayer.paused) {
videoOverlay.classList.remove('hidden');
}
} else {
videoContainer.classList.add('hidden');
audioContainer.classList.remove('hidden');
videoOverlay.classList.add('hidden');
}
});
// Format time (seconds to MM:SS)
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${minutes}:${secs < 10 ? '0' : ''}${secs}`;
}
// Update duration when metadata is loaded
mediaPlayer.addEventListener('loadedmetadata', function() {
durationDisplay.textContent = formatTime(mediaPlayer.duration);
});
// Show overlay when video ends
mediaPlayer.addEventListener('ended', function() {
playPauseBtn.innerHTML = '<i class="fas fa-play"></i>';
if (isVideoMode) videoOverlay.classList.remove('hidden');
});
// Initialize
mediaPlayer.volume = volumeControl.value;
// Animate audio bars when playing
mediaPlayer.addEventListener('play', function() {
const audioBars = document.querySelectorAll('.audio-bar');
audioBars.forEach(bar => {
bar.style.animationPlayState = 'running';
});
});
mediaPlayer.addEventListener('pause', function() {
const audioBars = document.querySelectorAll('.audio-bar');
audioBars.forEach(bar => {
bar.style.animationPlayState = 'paused';
});
});
// Optional: Replace with your video URL
function setMediaSource(url, posterUrl) {
document.getElementById('mediaSource').src = url;
mediaPlayer.poster = posterUrl || '';
mediaPlayer.load();
// Update thumbnail in audio mode
if (posterUrl) {
const audioThumbnail = document.querySelector('#audioContainer img');
if (audioThumbnail) {
audioThumbnail.src = posterUrl;
}
}
}
// Example of how to set a new video URL (you can call this function when needed)
// setMediaSource('YOUR_NEW_VIDEO_URL.mp4', 'YOUR_THUMBNAIL_URL.jpg');
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=josejuan314/audiovideoswitch" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |