已选中 Jplayer 播放列表添加复选框

Jplayer Playlist add on check box selected

我想使用复选框将播放列表添加到 jplayer,当我单击该复选框时,url 必须添加到 jplayer 播放列表,当我单击该复选框时,我得到了 url具体 url 但我无法添加到我的播放列表中 请任何人帮助我,当我添加它时显示未定义

 //This array object      
var playList = new Array();

//this check box selected event, when i click on checkbox i am having item which bring the url "http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg"
self.Selected= function (item) {
 var url = Voiceurl();
 playList.push(url);
 console.log(playList);
 //this function i am calling to add to playlist
JplayerWithPlaylist(playList)
}


function JplayerWithPlaylist(playList) {
console.log(playList);
var cssSelector = {
    jPlayer: "#jquery_jplayer_1", 
    cssSelectorAncestor: "#jp_container_1"
};
var options = {
    swfPath: "./js", 
    supplied: "oga"
};
var myPlaylist = new jPlayerPlaylist(cssSelector, playList, options);
for (i = 0; i < playList.length; i++) {

    myPlaylist.add(playList[i])
};
};

 <div id="jquery_jplayer_1" class="jp-jplayer"></div>
  <div id="jp_container_1" class="jp-audio">
  <div class="jp-type-playlist">
  <div class="jp-gui jp-interface">
  <div class="my-row btn-group jp-controls">
   <button href="javascript:;" class="btn btn-default glyphicon glyphicon-step-backward jp-previous" tabindex="1"></button>
    <button href="javascript:;" class="btn btn-default glyphicon glyphicon-play jp-play" tabindex="1"></button>
    <button href="javascript:;" class="btn btn-default glyphicon glyphicon-pause jp-pause" tabindex="1"></button>
    <button href="javascript:;" class="btn btn-default glyphicon glyphicon-step-forward jp-next" tabindex="1"></button>
   <button href="javascript:;" class="btn btn-default glyphicon glyphicon-stop jp-stop" tabindex="1"></button>
    <button href="javascript:;" class="btn btn-default glyphicon glyphicon-volume-off jp-mute" tabindex="1" title="mute"></button>
  <button href="javascript:;" class="btn btn-default glyphicon glyphicon-volume-down jp-unmute" tabindex="1" title="unmute"></button>
  <button href="javascript:;" class="btn btn-default glyphicon glyphicon-volume-up jp-volume-max" tabindex="1" title="max volume"></button>
   </div>
  </div>
  <div class="jp-playlist">
    <ul class="list-unstyled">
  <li></li>
  </ul>
 </div>
 </div>

请阅读http://jplayer.org/latest/demo-02-jPlayerPlaylist/

为什么要在每次添加时创建一个新的播放列表?这是非常昂贵的,只会覆盖你的另一个。

在页面加载时创建播放列表并在勾选复选框时添加到播放列表。

您似乎将 url 推入播放列表,然后将每个 url 添加到播放列表,这是不正确的。

jPlayerPlaylistadd() 方法采用对象而不是字符串作为参数:

例如

myPlaylist.add({
  title:"Your Face",
  artist:"The Stark Palace",
  mp3:"http://www.jplayer.org/audio/mp3/TSP-05-Your_face.mp3",
  oga:"http://www.jplayer.org/audio/ogg/TSP-05-Your_face.ogg",
  poster: "http://www.jplayer.org/audio/poster/The_Stark_Palace_640x360.png"
});

另外 item 未在您的函数中使用。

试试这个:

$(function() {
    var jPlayerPlaylistConfig = {
        cssSelector: {
            jPlayer: "#jquery_jplayer_1", 
            cssSelectorAncestor: "#jp_container_1"
        },
        options: {
            swfPath: "./js", 
            supplied: "oga"
        },
        playlist: []
    };

    var myPlaylist = new jPlayerPlaylist(jPlayerPlaylistConfig.cssSelector, jPlayerPlaylistConfig.playList, jPlayerPlaylistConfig.options);

    //this check box selected event, when i click on checkbox i am having item which bring the url "http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg"
    self.Selected = function () {
         var url = Voiceurl();
         console.log(url); //Make sure URL actually exists

         myPlaylist.add({
            mp3: url,
         });
    }
});

问我是否需要更多帮助。