2012-06-19 21 views
0

我有一個jplayer播放列表,從XML文件加載並轉換成json。我正在嘗試添加一個分享按鈕(只是一箇中央的按鈕,而不是播放列表中的每首歌曲),同時我已經成功創建了將標題添加到共享URL的代碼,但我無法弄清楚如何拉取參數關閉網址以確保當用戶關注該網站時播放共享歌曲。我正在修改播放列表文件,特別是選擇功能。我的網站是本地的,所以我不能共享鏈接,但我可以發佈播放列表代碼的修改部分。Jplayer分享按鈕 - 從URL拉參數

感謝您的任何幫助,可以給我! 斯蒂芬

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;   
    } 
    } 
    }, 

回答

0

如果我理解正確,您需要根據當前媒體生成一個URL,也想知道哪些媒體當前播放,如果打在所有。對?

好然後,這裏有一些想法:

  • JPlayerPlaylist附加this.current(這裏和進一步this被用於播放列表對象的上下文中使用的)具有一個內部屬性,該屬性將存儲的目前的索引選定/播放媒體。要獲得該對象,您需要訪問this.playlist[this.current]。你已經在你提供的代碼中沿着這條線做了一些事情。

  • 如果你想知道玩家在某個特定時間的狀態。最簡單的方法是訪問$("#your_jPlayer_Id").data("jPlayer").status.paused,如果玩家暫停,則返回true

  • 我也加入了一些語句playpause方法,比如設置按鈕的上暫停和恢復它回到有效的URL上playhref#