4

我需要做的是在锚点或按钮单击(总共 5 个)上更改 jPlayer 流源,而无需刷新页面或停止播放器。那可能吗?

JAVASCRIPT

jQuery(document).ready(function(){

        var stream = {
            title: "ABC Jazz",
            mp3: "http://listen.radionomy.com/abc-jazz"
        },
        ready = false;

        jQuery("#jquery_jplayer_master").jPlayer({
            ready: function (event) {
                ready = true;
                jQuery(this).jPlayer("setMedia", stream); //.jPlayer("play")
            },
            pause: function() {
                jQuery(this).jPlayer("clearMedia");
            },
            error: function(event) {
                if(ready && event.jPlayer.error.type === jQuery.jPlayer.error.URL_NOT_SET) {
                    // Setup the media stream again and play it.
                    jQuery(this).jPlayer("setMedia", stream).jPlayer("play");
                }
            },
            swfPath: "js",
            supplied: "mp3",
            preload: "none",
            wmode: "window",
            keyEnabled: false
        });

    });

<a id="lounge" href="javascript:void(0)">Click for Lounge music</a>
<a id="rock" href="javascript:void(0)">Click for Rock music</a>
.
.
<a id="dance" href="javascript:void(0)">Click for Dounge music</a>
4

1 回答 1

1

经过数小时的搜索后找到解决方案。

只需将其添加到您的代码中(根据您的示例):

$("#jquery_jplayer_master").jPlayer('destroy');
// And then call again your js code with new params
于 2016-02-14T18:39:52.007 回答