1(function($) { 2 'use strict'; 3 4 // Inicializar reproductores - similar a Radio Player 5 function initRadioPlayer() { 6 console.log('Glam Radio: Inicializando reproductores...'); 7 console.log('Glam Radio: Encontrados', $('.glam-radio-player').length, 'reproductores'); 8 console.log('Glam Radio: glamRadioSimple disponible?', typeof glamRadioSimple !== 'undefined'); 9 10 $('.glam-radio-player').each(function() { 11 const $player = $(this); 12 13 // Evitar inicialización múltiple 14 if ($player.data('glam-radio-initialized')) { 15 console.log('Glam Radio: Reproductor ya inicializado, saltando...'); 16 return; 17 } 18 console.log('Glam Radio: Inicializando nuevo reproductor'); 19 $player.data('glam-radio-initialized', true); 20 21 const $audio = $player.find('audio'); 22 const $btn = $player.find('.glam-radio-play-btn'); 23 const $track = $player.find('.glam-radio-track'); 24 const $label = $player.find('.glam-radio-label'); 25 const $volumeBtn = $player.find('.glam-radio-volume-btn'); 26 const $info = $player.find('.glam-radio-info'); 27 28 const streamUrl = $player.data('stream-url') || (typeof glamRadioSimple !== 'undefined' ? glamRadioSimple.stream_url : ''); 29 30 if ($audio.length === 0 || !streamUrl) { 31 console.error('Glam Radio: No se encontró el elemento audio o stream URL'); 32 if ($track.length) { 33 $track.text('Error: URL del stream no configurada'); 34 } 35 return; 36 } 37 38 const audio = $audio[0]; 39 let isPlaying = false; 40 let isProcessing = false; 41 let isMuted = false; 42 let metadataInterval = null; 43 44 // Configuración inicial del audio 45 audio.preload = 'none'; 46 if (isFinite(1) && 1 >= 0 && 1 <= 1) { 47 audio.volume = 1; 48 } 49 audio.muted = false; 50 51 // Establecer la fuente directamente 52 audio.src = streamUrl; 53 audio.removeAttribute('crossorigin'); 54 55 // Control de mute/unmute 56 $volumeBtn.on('click', function(e) { 57 e.preventDefault(); 58 e.stopPropagation(); 59 60 if (isMuted) { 61 audio.muted = false; 62 isMuted = false; 63 } else { 64 audio.muted = true; 65 isMuted = true; 66 } 67 updateVolumeIcon(); 68 }); 69 70 function updateVolumeIcon() { 71 const $icon = $volumeBtn.find('.glam-radio-volume-icon'); 72 73 if (isMuted) { 74 $icon.html('<path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v2.21l2.45 2.45c.03-.2.05-.41.05-.63zm2.5 0c0 .94-.2 1.82-.54 2.64l1.51 1.51C20.63 14.91 21 13.5 21 12c0-4.28-2.99-7.86-7-8.77v2.06c2.89.86 5 3.54 5 6.71zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73l-9-9L4.27 3zM12 4L9.91 6.09 12 8.18V4z"/>'); 75 } else { 76 $icon.html('<path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z"/>'); 77 } 78 } 79 80 // Inicializar icono de volumen 81 updateVolumeIcon(); 82 83 // Función para obtener metadatos del stream 84 let metadataRequestInProgress = false; 85 let lastMetadataCheck = 0; 86 87 function fetchMetadata() { 88 console.log('Glam Radio: fetchMetadata() llamada'); 89 console.log('Glam Radio: isPlaying =', isPlaying); 90 91 // Verificar condiciones básicas 92 if (!isPlaying) { 93 console.log('Glam Radio: fetchMetadata cancelada
93- no está reproduciendo'); 94 return; 95 } 96 97 // Evitar solicitudes muy frecuentes 98 const now = Date.now(); 99 console.log('Glam Radio: Tiempo desde última solicitud:', now - lastMetadataCheck); 100 if (metadataRequestInProgress || (now - lastMetadataCheck < 4000)) { 101 console.log('Glam Radio: fetchMetadata cancelada - solicitud en progreso o muy reciente'); 102 return; 103 } 104 105 if (typeof glamRadioSimple === 'undefined' || !glamRadioSimple.ajaxurl) { 106 console.error('Glam Radio: glamRadioSimple no está disponible'); 107 console.error('Glam Radio: typeof glamRadioSimple =', typeof glamRadioSimple); 108 return; 109 } 110 111 lastMetadataCheck = now; 112 metadataRequestInProgress = true; 113 114 console.log('Glam Radio: Solicitando metadatos para:', streamUrl); 115 console.log('Glam Radio: AJAX URL:', glamRadioSimple.ajaxurl); 116 117 $.ajax({ 118 url: glamRadioSimple.ajaxurl, 119 type: 'POST', 120 data: { 121 action: 'glam_radio_get_metadata', 122 stream_url: streamUrl, 123 nonce: glamRadioSimple.nonce 124 }, 125 timeout: 8000, 126 success: function(response) { 127 metadataRequestInProgress = false; 128 console.log('Glam Radio AJAX Success:', response); 129 130 if (response && response.success && response.data) { 131 const title = response.data.title || ''; 132 console.log('Glam Radio: TÃtulo recibido:', title); 133 134 if (title && title.trim() !== '' && title !== '-') { 135 // Mostrar el label y el ID de la canción 136 if ($label.length) { 137 $label.css('display', 'block'); 138 } 139 if ($track.length) { 140 $track.text(title.trim()); 141 console.log('Glam Radio: Texto actualizado exitosamente'); 142 } 143 } else { 144 // Si no hay tÃtulo, mantener "GLAM EN VIVO" sin label 145 if ($label.length) { 146 $label.hide(); 147 } 148 if ($track.length && !$track.find('.glam-live-text').length) { 149 $track.html('<span class="glam-live-text">GLAM EN VIVO</span>'); 150 } 151 console.log('Glam Radio: TÃtulo vacÃo o inválido en respuesta'); 152 } 153 } else { 154 // Si no hay respuesta exitosa, mantener "GLAM EN VIVO" sin label 155 if ($label.length) { 156 $label.hide(); 157 } 158 if ($track.length && !$track.find('.glam-live-text').length) { 159 $track.html('<span class="glam-live-text">GLAM EN VIVO</span>'); 160 } 161 console.log('Glam Radio: Respuesta sin éxito o sin data'); 162 } 163 }, 164 error: function(xhr, status, error) { 165 metadataRequestInProgress = false; 166 console.error('Glam Radio AJAX Error:', status, error); 167 if (xhr.responseText) { 168 console.error('Glam Radio: Response text:', xhr.responseText.substring(0, 200)); 169 } 170 }, 171 complete: function() { 172 metadataRequestInProgress = false;
173 } 174 }); 175 } 176 177 // Event listeners del audio - mÃnimos y eficientes 178 audio.addEventListener('play', function() { 179 console.log('Glam Radio: Evento PLAY detectado'); 180 isPlaying = true; 181 isProcessing = false; 182 $btn.addClass('playing'); 183 $player.addClass('playing'); 184 185 // Mantener "GLAM EN VIVO" hasta que llegue el ID 186 if ($track.length) { 187 $track.html('<span class="glam-live-text">GLAM EN VIVO</span>'); 188 } 189 // Ocultar el label hasta que llegue el ID 190 if ($label.length) { 191 $label.hide(); 192 } 193 194 // Verificar que glamRadioSimple está disponible 195 console.log('Glam Radio: glamRadioSimple disponible?', typeof glamRadioSimple !== 'undefined'); 196 if (typeof glamRadioSimple !== 'undefined') { 197 console.log('Glam Radio: ajaxurl:', glamRadioSimple.ajaxurl); 198 console.log('Glam Radio: nonce:', glamRadioSimple.nonce); 199 } 200 201 // Iniciar obtención de metadatos cada 5 segundos (igual que Radio Player) 202 if (metadataInterval) { 203 clearInterval(metadataInterval); 204 } 205 console.log('Glam Radio: Configurando intervalo de metadatos'); 206 metadataInterval = setInterval(function() { 207 console.log('Glam Radio: Intervalo ejecutado, llamando fetchMetadata'); 208 fetchMetadata(); 209 }, 5000); 210 // Obtener metadatos después de un breve delay para que el stream esté activo 211 console.log('Glam Radio: Programando primera solicitud de metadatos en 3 segundos'); 212 setTimeout(function() { 213 console.log('Glam Radio: Timeout ejecutado, llamando fetchMetadata'); 214 fetchMetadata(); 215 }, 3000); 216 }); 217 218 audio.addEventListener('pause', function() { 219 isPlaying = false; 220 isProcessing = false; 221 metadataRequestInProgress = false; 222 $btn.removeClass('playing'); 223 $player.removeClass('playing'); 224
225 // Volver al estado inicial: solo "GLAM EN VIVO" 226 if ($label.length) { 227 $label.hide(); 228 } 229 if ($track.length) { 230 $track.html('<span class="glam-live-text">GLAM EN VIVO</span>'); 231 } 232 233 // Detener obtención de metadatos 234 if (metadataInterval) { 235 clearInterval(metadataInterval); 236 metadataInterval = null; 237 } 238 }); 239 240 audio.addEventListener('loadstart', function() { 241 $player.addClass('loading'); 242 }); 243 244 audio.addEventListener('canplay', function() { 245 $player.removeClass('loading'); 246 }); 247 248 audio.addEventListener('waiting', function() { 249 $player.addClass('buffering'); 250 }); 251 252 audio.addEventListener('playing', function() { 253 $player.removeClass('buffering loading'); 254 }); 255 256 audio.addEventListener('error', function(e) { 257 console.error('Glam Radio: Error en audio:', e, audio.error); 258 $player.removeClass('loading buffering playing'); 259 isPlaying = false; 260 isProcessing = false; 261 $btn.removeClass('playing'); 262 263 if ($track.length) { 264 let errorMsg = 'Error al reproducir'; 265 if (audio.error) { 266 switch(audio.error.code) { 267 case audio.error.MEDIA_ERR_ABORTED: 268 errorMsg = 'Reproducción cancelada'; 269 break; 270 case audio.error.MEDIA_ERR_NETWORK: 271 errorMsg = 'Error de red'; 272 break; 273 case audio.error.MEDIA_ERR_DECODE: 274 errorMsg = 'Error de decodificación'; 275 break; 276 case audio.error.MEDIA_ERR_SRC_NOT_SUPPORTED: 277 errorMsg = 'Formato no soportado'; 278 break; 279 } 280 } 281 $track.text(errorMsg); 282 } 283 }); 284 285 // Control de play/pause - simplificado y rápido como Radio Player 286 $btn.on('click', function(e) { 287 e.preventDefault(); 288 e.stopPropagation(); 289 290 if (isProcessing) { 291 return; 292 } 293 294 if (isPlaying) { 295 // Pausar 296 isProcessing = true; 297 audio.pause(); 298 } else { 299 // Reproducir 300 isProcessing = true; 301 audio.muted = isMuted; 302 303 // Llamar play() directamente - el navegador maneja el resto 304 const playPromise = audio.play(); 305 306 if (playPromise !== undefined) { 307 playPromise.then(function() { 308 isProcessing = false; 309 }).catch(function(error) { 310 isProcessing = false; 311 console.error('Glam Radio: Error al reproducir:', error); 312 313 if ($track.length) { 314 if (error.name === 'NotAllowedError') { 315 $track.text('Haz clic para permitir la reproducción'); 316 } else if (error.name === 'NotSupportedError') { 317 $track.text('Formato no soportado'); 318 } else { 319 $track.text('Error al reproducir'); 320 } 321 } 322 }); 323 } else { 324 // Fallback para navegadores antiguos 325 audio.play(); 326 isProcessing = false;
327 } 328 } 329 }); 330 331 audio.addEventListener('ended', function() { 332 isPlaying = false; 333 $btn.removeClass('playing'); 334 $player.removeClass('playing'); 335 336 // Detener obtención de metadatos 337 if (metadataInterval) { 338 clearInterval(metadataInterval); 339 metadataInterval = null; 340 } 341 }); 342 }); 343 } 344 345 // Inicializar cuando el DOM esté listo 346 $(document).ready(function() { 347 initRadioPlayer(); 348 }); 349 350 // Reinicializar si se carga contenido dinámicamente 351 $(document).on('glam-radio-init', function() { 352 initRadioPlayer(); 353 }); 354 355})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.