0

我正在为我运行的音乐博客制作音频播放器,但我似乎无法让 jPlayer 在我的网站上正常工作。现在,我已将其设置为只有管理员才能查看播放器(因为它不起作用),但我制作了一个小测试网站,以便您也能明白我的意思。

该播放器在 Firefox 中运行良好,但在 Chrome 中无法正常运行。我有一种感觉,它与它用于 Firefox 的 flash 回退有关,但我不明白为什么它也不能在 Chrome 上运行。它似乎根本不想加载/流式传输歌曲。

我制作了一些功能,因此可以在您正在查看的任何页面上动态添加歌曲。我相信我正确设置了所有内容。我使用一个数组作为歌曲的标题和 MP3 的 URL,它们是由 WordPress 动态添加的。每次添加新歌时,我都会调用下面的 JavaScript 函数 add_song...

function add_song(title, mp3)
{
    theTitles[index] = title;
    theMP3s[index] = mp3;
    index++;
}

然后对于 document.ready 函数,我使用我创建的另一个名为 get_playlist() 的函数来设置我的 jPlayer;

function get_playlist()
{
    var playlist = new Array();

    for(var i = 0; i < theTitles.length; i++)
    {
        playlist[i] = {title: theTitles[i], mp3: theMP3s[i]};
    }
    return playlist;
}

$(document).ready(function()
{
    var playlist = get_playlist();
    new jPlayerPlaylist({
        jPlayer: "#jquery_jplayer_1",
        cssSelectorAncestor: "#jp_container_1",
        oggSupport:false
    }, playlist, {
        swfPath: "/js",
        supplied: "mp3",
        wmode: "window"
    });
});

我有一种感觉,我错过了一些简单的东西,为什么它可以在 Firefox 而不是 Chrome 上运行,但我不知道它是什么。但是,如果您通过按下实际帖子上的播放按钮开始播放其中一首歌曲,然后停止它,然后尝试在顶级播放器中播放它,它工作正常。例如,尝试在顶级播放器中播放第一首歌曲,它不会奏效。然后单击实际 Seasfire 帖子上的播放按钮,暂停它,然后再次尝试顶级播放器,它会起作用。这是我到测试站点的网址,因此如果您有任何问题,您可以自己查看播放器。

谢谢大家!

4

1 回答 1

0

stackoverflow 不会让我现在登录,但我是原始发帖人。

索引在我使用它之前被定义和初始化,所以这不是问题。我使用的整个javascript是......

<script type="text/javascript">

    var index = 0;
    var theTitles = new Array();
    var theMP3s = new Array();

    function add_song(title, mp3)
    {
        theTitles[index] = title;
        theMP3s[index] = mp3;
        index++;
    }

    function get_playlist()
    {
        var playlist = new Array();

        for(var i = 0; i < theTitles.length; i++)
        {
            playlist[i] = {title: theTitles[i], mp3: theMP3s[i]};
        }
        return playlist;
    }


    $(document).ready(function()
    {
        var playlist = get_playlist();
        new jPlayerPlaylist({
            jPlayer: "#jquery_jplayer_1",
            cssSelectorAncestor: "#jp_container_1"
        }, playlist, {
            swfPath: "/js",
            supplied: "mp3",
            wmode: "window"
        });
    });
    //]]>
    </script>
于 2013-01-29T22:19:27.730 回答