Unreliable API
Unreliable API

Reputation: 21

YouTube's player.loadPlaylist and cuePlaylist not functioning as of 2013-01-30

Forgive me if this is the wrong venue for this problem, but Google's deprecated developer forums recommend I go here.

Following is some heavily-simplified code meant to demonstrate the problem:

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script type="text/javascript">
            $(
                function() {
                    /*
                    This one second delay is just there to give the player time
                    to load.  It's more complicated in my proper implementation.
                    */
                    window.setTimeout(
                        function() {
                            var player = document.getElementById('player');
                            /*
                            Shocker, it doesn't work, regardless of playlist ID.
                            */
                            player.loadPlaylist(
                                {
                                    list:  'PL63FA01F86C3FE49A'
                                }
                            );
                        },
                        1000
                    );
                }
            );
        </script>
    </head>
    <body>
        <object data="http://www.youtube.com/apiplayer?enablejsapi=1&version=3" height="360" id="player" width="600">
            <param name="AllowScriptAccess" value="always">
            <param name="movie" value="http://www.youtube.com/apiplayer?enablejsapi=1&version=3">
        </object>
    </body>
</html>

Upvotes: 2

Views: 2463

Answers (2)

Tiago Rold&#227;o
Tiago Rold&#227;o

Reputation: 10649

I've stumbled on this very problem while on a coding sprint, this week:

The loadPlaylist/cuePlaylist methods require both the list parameter and the listType parameter (it isn't very clear in the docs).

So, the code:

player.loadPlaylist(
    {
         list:  'PL63FA01F86C3FE49A',
         listType: 'playlist'
    }
);

Should work fine, both with SWF and HTML embeds. Jeff Posnick's recomendations on his answer to this question apply as well of course, but I've tested it to work in both scenarios.

listType can be 'list', 'search' or 'user_uploads', and list represents a list id or array of video ids, a search query, ou a user id, respectively.

Upvotes: 1

Jeff Posnick
Jeff Posnick

Reputation: 56104

A few comments on your code before getting to the question: first, if you're sure that you need to use the AS3 chromeless player, you really should use SWFObject to add it to your page to ensure that the proper <object> and <embed> tags are both used. If you only specify <object> tags then it will only work in Internet Explorer.

Also, you should have a onYouTubePlayerReader(playerId) handler in your code to detect when the player is fully loaded and ready to respond to API calls. That's much, much more reliable than attempting to do that via a window.setTimeout().

Regarding your actual question, I'm not sure that the chromeless AS3 player ever supported working with playlists. Was this code previously working that recently stopped? I'd imagine that you'd have a much better experience using the iframe embedded player and specifying controls=0 if you really don't want controls (but hiding the controls takes away from the playlist experience).

Upvotes: 0

Related Questions