jPlayer text link does not play

限于喜欢 提交于 2019-12-07 08:38:47

问题


i am trying to do a basic jplayer text link on click to play an mp3 file, but i am unable to get it to function as 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


回答1:


there were a couple of things..

  1. this, when used within a click event refers to the clicked element, not your jPlayer element
  2. there is no such jPlayer method as setFile - it's setMedia

try this:

$(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");
    });
});


来源:https://stackoverflow.com/questions/8524706/jplayer-text-link-does-not-play

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!