-1

var player;

function onYouTubePlayerAPIReady() {
  player = new YT.Player('video', {
    events: {
      'onReady': onPlayerReady
    }
  });
}

function onPlayerReady(event) {
  player.playVideo();
}
<script src="//www.youtube.com/player_api"></script>

<iframe id="video" src="//www.youtube.com/embed/TTQK9aWZVds?enablejsapi=1"></iframe>

The above code is to run the video on mobile browser, but it is not playing!

it's working in web browser

  • You are aware that browser vendors limit the ability to auto-play videos on mobile to a very specific set of circumstances, right? – CBroe Jan 30 '18 at 12:18

2 Answers2

0

Check out this link.

"Javascript is limited by the 'same origin policy' for security reasons so that a malicious script cannot contact a remote server and send sensitive data."

Jeremy
  • 1,384
  • 3
  • 10
  • 24
  • – suresh 10decoders Jan 30 '18 at 12:31
  • I updated my answer again with a link to another stack overflow topic, were the answer explains this scenario very good. – Jeremy Jan 30 '18 at 12:39
0

Unfortunately video autoplay (as well as JS triggered playing) is forbidden on mobile devices. Video should be started by user action only. https://developers.google.com/youtube/iframe_api_reference?csw=1#Examples

Anarion
  • 1,048
  • 6
  • 16