Jplayer共享按钮 - 从URL中提取参数

时间:2012-06-19 19:06:00

标签: jquery jplayer url-parameters

我有一个带有播放列表的jplayer,它从xml文件加载并转换为json。我正在尝试添加一个分享按钮(只是一个中央按钮,不在播放列表中的每首歌曲上),虽然我已经成功创建了将标题添加到URL以进行共享的代码,但我无法弄清楚如何拉动参数关闭URL以确保当用户关注该站点的链接时播放共享歌曲。我正在修改播放列表文件,特别是select函数。我的网站是本地的,所以我无法共享链接,但我可以发布播放列表代码的修改部分。

感谢你的帮助,你可以给我!! 斯蒂芬

Link to original playlist file

修改了选择功能:

    select: function(index) {
    $.urlParam = function(homily) {
            var results = new RegExp('[\\?&]' + homily + '=([^&#]*)').exec(window.location.href);
            return results[1] || 0;
            console.log($.urlParam('homily'));
        index = (index < 0) ? this.original.length + index : index; // Negative index relates to end of array.
        if(encodeURIComponent($.urlParam('homily')) === this.playlist[index].title) {
        this.current = this.playlist[index].title;
        $(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
        } else if (0 <= index && index < this.playlist.length) {
            this.current = index;
            this._highlight(index);
            $(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
        var downloadBtn=this.cssSelector.cssSelectorAncestor+' [class^="download_btn"]';
            $(downloadBtn).attr('href', encodeURIComponent(this.playlist[this.current].mp3));
            var shareBtn=this.cssSelector.cssSelectorAncestor+' [class^="share_btn"]';
            $(shareBtn).attr('href', "?homily=" + decodeURIComponent(this.playlist[this.current].title));

        } else {
            this.current = 0;           
    }
    }
    },

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要根据当前媒体生成网址,并且您还想知道当前播放的媒体。正确?

好的,这里有一些想法:

  • JPlayerPlaylist附加组件具有内部属性this.current(此处和另外this用于播放列表对象的上下文中),它将存储当前所选/播放媒体的索引。要获取该对象,您将访问this.playlist[this.current]。您已经在代码中执行了这些操作。

  • 如果您想在某个特定时间了解玩家的状态。最简单的方法是访问$("#your_jPlayer_Id").data("jPlayer").status.paused,如果播放器暂停,则返回true

  • 我还会在playpause方法中添加一些语句,例如在暂停时将按钮的href设置为#并将其还原回有效的网址在play