O
O
Oslar2019-05-19 22:33:17
JavaScript
Oslar, 2019-05-19 22:33:17

Why doesn't iframe autoplay start when clicking on a button on mobile?

$(".butt_play").click(function(){
        var dataYoutube = $(this).parents('.video').attr('data-youtube');
        $(this).parents('.video').html('<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'+ dataYoutube +'?rel=0&autoplay=1&enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>');
        dataYoutube.playVideo();
    });


<div class="tc video container">
    <div class="video_about_park">
      <div class="video" data-youtube='Q-gw49LH1oA'>
        <img src="images/img_zakaz.png"  id="movie" class="butt_play img-responsive" alt="" />
      </div>
    </div>
  </div>


With such a script, the following comes out, when you click on the button, the button is deleted and the video from YouTube is substituted. On the computer everything is fine, when you click there is autorun, but on the mob. no.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DemonIa, 2019-05-22
@Oslar

It is unlikely that you will succeed. Autoplay will not work on mobile, for security reasons.
If the video is short and without sound - you can make a gif-animation and put it as a background-image.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question