JW Player播放列表仅在IE中随机加载,每次都在FF中正常工作

时间:2010-02-08 16:11:22

标签: asp.net javascript jwplayer

播放列表每次都在FF中加载,但仅在IE(6-8)中第一次加载,之后只是随机加载。 如果我警告引发的错误,我会得到“TypeError:playerReady is undefined”。

我的代码看起来不错,显然有效,因为FF完美地显示了播放列表。我不知道如何解决这个问题。任何人吗?

<script type='text/javascript'>
        var so = new SWFObject('/UI/Flash/player.swf', 'ply', '<%=FlashWidth %>', '<%=FlashHeight %>', '9', '#ffffff'),
            playlistURL = '<%=PlaylistURL %>',
            imageURL = '<%=GetBackgroundImageUrl() %>';
            so.addParam('allowfullscreen', 'true');
            so.addParam('allowscriptaccess', 'always');
        if (playlistURL !== '') {
            so.addVariable('playlistfile', playlistURL);
            so.addVariable('playlist', 'none');
            so.addVariable('enablejs', 'true');
        }
        else {
            so.addVariable('file', '<%=FlashURL %>');
        }   

        if (imageURL.length > 0) {
         so.addVariable('image', imageURL);
        }
        so.write('preview<%=PlayerID %>');
    </script>

2 个答案:

答案 0 :(得分:0)

玩家在完成设置过程后会调用pl​​ayerReady函数。你碰巧定义了那个函数,然后把它设置为undefined吗?这可能会导致错误。

此外,您使用的是哪个版本的播放器?

so.addVariable('enablejs', 'true');

我不相信自3.X播放器以来一直是flashvar,不再受支持。

最佳,

扎克

开发者,LongTail视频

答案 1 :(得分:0)

不确定我是如何解决它的,但这是实际有效的最终代码:

HTML PAGE:

<script type='text/javascript'>
        var so = new SWFObject('/UI/Flash/player.swf', 'ply', '700', '345', '9', '#ffffff'),
            playlistUrl = 'XML-PLaylist',
            imageURL = '/ImageVault/Images/conversionFormat_2/id_1577/scope_0/ImageVaultHandler.aspx';
            so.addParam('allowfullscreen', 'true');
            so.addParam('allowscriptaccess', 'always');
            so.addParam('wmode', 'opaque');
        if (playlistUrl !== '') {
            so.addVariable('playlistfile', playlistUrl);
            so.addVariable('playlist', 'none');
            so.addVariable('controlbar', 'bottom');
            so.addVariable('backcolor', '0xDDE5FF');
            so.addVariable('frontcolor', '0x142864');
            so.addVariable('screencolor', '0xffffff');
            so.addVariable('enablejs', 'true');
            so.addVariable('overstretch', 'true');
        }
        else {
            so.addVariable('file', '');
        }   

        if (imageURL.length > 0) {
         so.addVariable('image', imageURL);
        }
        so.write('preview');
    </script>

这是JavaScript:

    try {

            var playlistReady = playerReady;
        } cat

ch (err) {
        //alert('1' + err);
    }

    playerReady = function(obj) {
        setTimeout(function() { checkPlaylistLoaded(obj) }, 1);
        try {
            playlistReady(obj);
        } catch (err) {
            //alert(err);
        }
    }

    function itemHandler(obj) {
        var item = obj['index'];
        var playlist = $("#" + obj['id']).next();
        var currentItem = 0;
        playlist.children().each(function() {
            if (currentItem == item) {
                $(this).addClass("playing");
            } else {
                $(this).removeClass("playing");
            }
            currentItem++;
        });
    }


    function checkPlaylistLoaded(obj) {
        //debugger;
        var player = document.getElementById(obj['id']),
            jsPlaylist = player.getPlaylist();
        if (jsPlaylist.length > 0) {
            var playlist = createPlaylist(obj);
            populatePlaylist(player, jsPlaylist, playlist);
            player.addControllerListener("PLAYLIST", "playlistHandler");
            player.addControllerListener("ITEM", "itemHandler");
            player.addControllerListener("STOP", "showPlaylist");
            player.addModelListener("STATE", "stateListener");
        } else {
            setTimeout(function() { checkPlaylistLoaded(obj) }, 150);
        }
    }

    function stateListener(obj) {
        if (obj.newstate === 'PLAYING') {
            hidePlaylist();
        }
        if (obj.newstate === 'PAUSED') {
            showPlaylist();
        }
    }

    function createPlaylist(obj) {
        var playerDiv = $("#" + obj['id']);
        playerDiv.after("<div class='jw_playlist_playlist'></div>");
        return playerDiv.next();
    }

    function hidePlaylist() {
        $('.jw_playlist_playlist').animate({ left: "-320px" }, 1000);
    }

    function showPlaylist() {
        $('.jw_playlist_playlist').animate({ left: "-10px" }, 1000);
    }

    function playlistHandler(obj) {
        var player = document.getElementById(obj['id']),
            jsPlaylist = player.getPlaylist(),
            playerDiv = $("#" + obj['id']),
            playlist = playerDiv.next();
        populatePlaylist(player, jsPlaylist, playlist);
    }

    function populatePlaylist(player, jsPlaylist, playlist) {
        playlist.empty();
        for (var i = 0; i < jsPlaylist.length; i++) {
            var jsItem = jsPlaylist[i];
            var alternate = "even";
            if (i % 2) {
                alternate = "odd";
            }
            playlist.append("<div id='" + getItemId(jsItem) + "' class='jw_playlist_item " + alternate + "'>" + dump(jsItem) + "</div>");
        }
        var playlistItem = 0;
        playlist.children().each(function() {
            var currentItem = playlistItem;
            $(this).click(function() {
                player.sendEvent("ITEM", currentItem);
            });
            playlistItem++;
        });
    }

    function getItemId(arr) {
        var output = '${link}',
            variables = getVars(output),
            j;

        for (j = 0; j < variables.length; j++) {
            var variable = variables[j],
                varName = variable.replace('${', '').replace('}', ''),
                value = arr[varName];
            if (!value) {
                value = '';
            }
            output = output.replace(variable, value);
        }
        return output;
    }

    function dump(arr) {
        var output = "<div class='jw_playlist_title'>${title}</div><div class='jw_playlist_description'>${description}</div>",
            variables = getVars(output),
            j;
        for (j = 0; j < variables.length; j++) {
            var variable = variables[j],
                varName = variable.replace('${', '').replace('}', ''),
                value = arr[varName];
            if (!value) {
                value = '';
            }
            output = output.replace(variable, value);
        }
        return output;
    }

    function dumpText(arr) {
        var dumped_text = "";
        if (typeof (arr) == 'object') {
            for (var item in arr) {
                var value = arr[item];
                if (typeof (value) == 'object') {
                    dumped_text += "<div class='" + item + "'>";
                    dumped_text += dump(value);
                    dumped_text += "</div>";
                } else {
                    dumped_text += "<div class='" + item + "'>" + value + "</div>";
                }
            }
        } else {
            dumped_text += arr + " (" + typeof (arr) + ")";
        }
        return dumped_text;
    }

    function getVars(str) {
        return str.match(/\$\{(.*?)\}/g);
    }