jplayer multiple mp3 file links in one page

前端 未结 4 606
旧时难觅i
旧时难觅i 2021-01-16 00:15

I use jplayer in my page and when clicked a link I want to play the clicked one. However every time test1.mp3 is played. How can I solve it? The code is below:

the p

4条回答
  •  死守一世寂寞
    2021-01-16 00:55

    Hey you can do the following.

    I instantiate the player on page load:

    jQuery("#jquery_jplayer_1").jPlayer({
      swfPath: "http://www.jplayer.org/latest/js/Jplayer.swf",
      supplied: "mp3",
      wmode: "window",
      preload:"auto",
      autoPlay: true,
      errorAlerts:false,
      warningAlerts:false
    });
    

    Then inside a listener, which will be unique for every item, you need to: A) Fetch track name/URL, I guess you should be able to figure this out.

    B) Pass the track to the setMedia

      jQuery("#jquery_jplayer_1").jPlayer("setMedia", {
        mp3: "http:xxxx.rackcdn.com/"+track+".MP3"
      });
    

    C) Play the track

      jQuery("#jquery_jplayer_1").jPlayer("play");
    

    To get the track Id you need to install listeners on your playable items(maybe a a playable class?) and get the track from that one.

提交回复
热议问题