javascript - Embedded Youtube videos not playing in mobile iOS Safari -


recently we've found bug exists only in safari on iphone(s) cannot pinpoint source of issue. when pressing play button video appears load closes immediately.

all answers i've found far aren't recent and/or don't solve problem. testing in browserstack giving me error: invalid css property declaration at: * www-embed-player-sprite-mode-vfl9mhoab.css file served youtube.

i'm open optional ways of handling embedded videos avoid issue.

the code:

#set($showvideo = $request.getparameter("showvideo")) #set($howitworksid = $placeholder.getattributevaluegroup().getattributevalue('product_howitworks', $sesshoppingcart.getlocale())) #set($embeddedurl = "https://www.youtube.com/embed/" + $howitworksid + "?rel=0") #set($hasvideoid = false) #if( $howitworksid && $howitworksid != "" )     #set( $hasvideoid = true ) #end  <div id="howitworksmodal" class="modal-howitworks modal fade">   <div class="modal-dialog modal-lg">     <div class="modal-content">         <button type="button" class="close js-modalclose close--howitworks" data-dismiss="modal">             <span aria-hidden="true">&times;</span>             <span class="sr-only">close</span>         </button>         <div>             <div class="prose howitworks-embedvideowrapper">               <div class="iframe-container">                     <iframe id="howitworks-modalversion" class="howitworks js-howitworks-iframe" width="100%" src="" frameborder="0" allowfullscreen preload></iframe>               </div>            </div>         </div>      </div>   </div> </div>      jqueryready(function() {              var videourl = "$embeddedurl";              // load destination video , autoplay when modal opens             $("#howitworksmodal").on('shown.bs.modal', function(ev) {                 ev.preventdefault();                 $("#howitworks-modalversion").attr("src", videourl + "&autoplay=1");                 console.log('clicked on');             });              // kill video when modal closed             $('#howitworksmodal').on('hidden.bs.modal', function (e) {                 $('.js-howitworks-iframe').each( function(){                     $(this).attr('src', '');                 });             });              // kill mobile video if playing while window resized             function mobilevideosource(){                 var mobileblock = $('#buynow-mobileblock'),                     howtovid_mobile = $('#howitworks-mobileversion');                  if (mobileblock.is(":hidden")) {                     // if mobile block hidden remove it's source                     howtovid_mobile.attr('src', '');                 } else {                     // if mobile block displayed add source                     howtovid_mobile.attr('src', videourl);                 }             }              sdi.window.on('resize', mobilevideosource);         }) 

mobilevideosource() being called , removing src when video opening. did not investigate why happening, restructured script remove iframe instead of src , inject new instance if (for whatever rare edge use case) screen resized down mobile , user wants watch video again:

function mobilevideosource() {   var mobileblock  = $('#buynow-mobileblock'),   currentvid     = $('#howitworks-mobileversion'),   videocontainer = $('.iframe-container')   new_iframe     = $('<iframe id="howitworks-mobileversion" class="howitworks" width="560" height="315" src="$embeddedurl" frameborder="0" allowfullscreen></iframe>');      if (mobileblock.is(":hidden")) {       currentvid.remove();     } else {       videocontainer.append(new_iframe);     }  } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -