JPlayer text link not playing

I am trying to make a basic jplayer text link when clicked to play an mp3 file, but I cannot make it work because there is no sound. here is the code

$(document).ready(function(){ $("#jquery_jplayer").jPlayer({ ready: function (event) { $('.voice').click(function(e) { e.preventDefault(); $(this).jPlayer("setFile", $(this).attr('href')).jPlayer("play"); }); }, swfPath: "/ui/core/js/jPlayer/", supplied: "mp3", wmode: "window" }); 

});

here is the html:

 <table> <tr> <td> <a href="music.mp3" class="voice">Listen</a> </td> </tr> </table> <div id="jquery_jplayer"></div> 

What am I missing?

thanks

+4
source share
1 answer

there were a few things.

  • this , when used in a click event, refers to the clicked element, not the jPlayer element
  • there is no jPlayer method like setFile - it setMedia

try the following:

 $(document).ready(function(){ $("#jquery_jplayer").jPlayer({ swfPath: "/ui/core/js/jPlayer/", supplied: "mp3", wmode: "window" }); $('.voice').click(function(e) { e.preventDefault(); $("#jquery_jplayer") .jPlayer("setMedia", {mp3: this.href }) .jPlayer("play"); }); }); 
+5
source

Source: https://habr.com/ru/post/1386575/


All Articles