Your content goes here. Edit or remove this text inline or in the module Content settings. You can also style every aspect of this content in the module Design settings and even apply custom CSS to this text in the module Advanced settings. Códigos para Vídeo en autoplay Primer código utilizado, fue muy bien durante mucho tiempo. Segund código utilizado, fue aconsejado por chatgpt Tercer código utilizado, fue aconsejado aún más por chatgpt script> (function($){ function setupVideo(el){ if(!el) return; // Si es nativo if(el.tagName && el.tagName.toLowerCase() === 'video'){ el.muted = true; el.volume = 0; el.loop = true; el.autoplay = true; el.playsInline = true; el.setAttribute('muted',''); el.setAttribute('playsinline',''); el.setAttribute('autoplay',''); el.setAttribute('loop',''); // controles (booleano) el.controls = true; try { el.load(); } catch(e){} const p = el.play(); if (p && p.catch) { p.then(()=>console.log('[Divi autoplay] OK video', el)) .catch(err=>console.warn('[Divi autoplay] BLOQUEADO video:', err, el)); } else { console.log('[Divi autoplay] play() sin promise (navegador antiguo)', el); } return; } // Si es iframe (YouTube/Vimeo) if(el.tagName && el.tagName.toLowerCase() === 'iframe'){ const src = el.getAttribute('src') || ''; if(!src) return; let newSrc = src; // YouTube if(src.includes('youtube.com') || src.includes('youtu.be')){ // OJO: requiere mute=1 para autoplay; playsinline=1 para iOS newSrc = addParams(src, { autoplay: 1, mute: 1, playsinline: 1, controls: 1 }); } // Vimeo if(src.includes('vimeo.com')){ newSrc = addParams(src, { autoplay: 1, muted: 1, loop: 1, controls: 1 }); } if(newSrc !== src){ el.setAttribute('src', newSrc); console.log('[Divi autoplay] iframe src actualizado', newSrc); } else { console.log('[Divi autoplay] iframe detectado (src sin cambios)', src); } } } function addParams(url, params){ try{ const u = new URL(url, window.location.href); Object.keys(params).forEach(k => u.searchParams.set(k, params[k])); return u.toString(); }catch(e){ // fallback cutre si URL() falla const sep = url.includes('?') ? '&' : '?'; return url + sep + Object.keys(params).map(k=>k+'='+encodeURIComponent(params[k])).join('&'); } } function run(){ const $scope = $('.lwp-video-autoplay .et_pb_video_box'); if(!$scope.length){ console.warn('[Divi autoplay] No encuentro .lwp-video-autoplay .et_pb_video_box'); return; } // 1) intenta videos nativos const vids = $scope.find('video').toArray(); // 2) intenta iframes (YouTube/Vimeo) const ifr = $scope.find('iframe').toArray(); console.log('[Divi autoplay] encontrados:', { boxes: $scope.length, videos: vids.length, iframes: ifr.length }); vids.forEach(setupVideo); ifr.forEach(setupVideo); } // Ejecuta varias veces: DOM ready, load, y reintento (por si Divi inyecta tarde) $(run); $(window).on('load', run); setTimeout(run, 800); setTimeout(run, 2500); // Observer: si Divi mete el módulo después, lo pillamos const obs = new MutationObserver(function(muts){ for(const m of muts){ if(m.addedNodes && m.addedNodes.length){ // si aparece algo que contenga nuestra clase, re-ejecuta const hit = Array.from(m.addedNodes).some(n => n.nodeType === 1 && (n.matches?.('.lwp-video-autoplay, .et_pb_video_box') || n.querySelector?.('.lwp-video-autoplay .et_pb_video_box')) ); if(hit){ run(); break; } } } }); obs.observe(document.documentElement, { childList:true, subtree:true }); })(jQuery);