Search code examples
javascriptiosyoutubeyoutube-apiswfobject

Making the YouTube JS API work with iOS, dealing with embedSWF?


I'm working with the JS API for YouTube and for displaying the video player, use of embedSWF is recommended by Google in the documentation, like this:

  <script type="text/javascript" src="swfobject.js"></script>    

  <div id="ytapiplayer">
    You need Flash player 8+ and JavaScript enabled to view this video.
  </div>

  <script type="text/javascript">

    var params = { allowScriptAccess: "always" };
    var atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/VIDEO_ID?enablejsapi=1&playerapiid=ytplayer&version=3","ytapiplayer", "425", "356", "8", null, null, params, atts);

  </script>

While this works fine on my computer and Android devices, on iOS the ytapiplayer div does not turn into an embedded player but instead just displays its original contents, i.e. the error message saying Flash player 8+ and JS are required.

Is it possible to get my this working on iOS? If so, how?

Thanks in advance!


Solution

  • Maybe you should try new YouTube iframe Player API? https://developers.google.com/youtube/iframe_api_reference

    It works with mobile devices without thinking about Flash. Embedding example:

    <script type="text/javascript" src="//www.youtube.com/iframe_api"></script>
    
    function onYouTubePlayerAPIReady() {
        var videoBox = document.getElementById('video1');
        videoBox.ytplayer = new YT.Player(videoBox, {
            videoId: 'kXDiGtgPL6E',
            playerVars: {
                //controls: 0,
                wmode:'transparent'
            },
            height: '200',
            width: '320'
        });
    }