简体   繁体   English

jplayer单击播放没有任何反应

[英]jplayer clicking play nothing happening

I am currently working with jPlayer to add some sound clips to my website, however when I click play, nothing happens...the page just reloads as if I have clicked a link, below is my HTML and my javascript, and also the altered DOM. 我目前正在与jPlayer合作,将一些声音片段添加到我的网站,但是,当我单击播放时,什么也没发生...该页面只是重新加载,就像我单击了一个链接一样,下面是我的HTML和我的javascript,以及修改过的DOM。

$("#jquery_jplayer").jPlayer({
            ready: function (event) {
                $('.voice').click(function(e) {
                    $(this).jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
                e.preventDefault();
                });
            },
            solution: "flash, html", // Flash with an HTML5 fallback.
            swfPath: "/media/js/jPlayer/",
            wmode: "window"
        });
});



   <li><a href="" rel="<?php echo base_url(); ?>media/uploads/audio/<?php echo $candidate_audio['url']; ?>" class="voice">Play Voice Over</a></li>

the flash holder 闪光灯架

<div id="jquery_jplayer"></div>

altered on domReady too.... 在domReady上也进行了更改。

<div id="jquery_jplayer" style="width: 0px; height: 0px;">
    <img id="jp_poster_0" style="width: 0px; height: 0px; display: none;">
    <object width="1" height="1" id="jp_flash_0" data="/media/js/jPlayer/Jplayer.swf" type="application/x-shockwave-flash" style="width: 0px; height: 0px;">
    <param name="flashvars" value="jQuery=jQuery&amp;id=jquery_jplayer&amp;vol=0.8&amp;muted=false">
    <param name="allowscriptaccess" value="always">
    <param name="bgcolor" value="#000000">
    <param name="wmode" value="window">
    </object>
 </div>

It's been a while since I used jPlayer, but I think this line: $(this).jPlayer("setFile"... is the problem. Since you're doing that in a click-handler, this will probably point to the wrong element. I would try this: 自从我使用jPlayer以来已经有一段时间了,但是我认为这一行: $(this).jPlayer("setFile"...是问题。由于您是在点击处理程序中执行thisthis可能指向错误的元素,我会尝试这样做:

$("#jquery_jplayer").jPlayer({
    ready: function (event) {
        var $this = $(this);
        $('.voice').click(function(e) {
            $this.jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
            e.preventDefault();
        });
    },
    solution: "flash, html", // Flash with an HTML5 fallback.
    swfPath: "/media/js/jPlayer/",
    wmode: "window"
});

This is exactly how it's working for me. 这正是它为我工作的方式。 Note the first line which assigns a click handler to block the default behavior of clicking a link... 请注意第一行分配了单击处理程序以阻止单击链接的默认行为...

$(document).ready(function(){

    $('[class^="jp-"]').click(function (e) { e.preventDefault(); });

    $("#jquery_jplayer").jPlayer({
       ready: function () {
           $(this).jPlayer("setMedia", {
               mp3: "/music/mySong.mp3"
            });
       },
       swfPath: "/jPlayer/js",
       supplied: "mp3",
       volume: 0.6
    });
});

In your case, you could try the following. 您可以尝试以下方法。 The preventDefault() should be the first item in the function... preventDefault()应该是函数中的第一项...

$(document).ready(function(){
    $("#jquery_jplayer").jPlayer({
        ready: function (event) {
            $('.voice').click(function(e) {
                e.preventDefault();  // <-- first item in this function
                $(this).jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
            });
        },
        solution: "flash, html", // Flash with an HTML5 fallback.
        swfPath: "/media/js/jPlayer/",
        wmode: "window"
    });
});

Also note that in your original posting, you've either made a simple typo on SO or a programming error. 另请注意,在您的原始帖子中,您已经对SO进行了简单的错字或编程错误。 There is an extra set of closing brackets, }); 还有一组右括号, }); or you've misplaced/left out the initial document.ready line. 或者您放错位置/未放置初始document.ready行。

        $("#jquery_jplayer").jPlayer({
            ready: function (event) {
                $('.voice').click(function(e) {
                    $(this).jPlayer("setFile", $(this).attr('rel')).jPlayer("play");
                e.preventDefault();
                });
            },
            solution: "flash, html", // Flash with an HTML5 fallback.
            swfPath: "/media/js/jPlayer/",
            wmode: "window"
        }); 
});  // <--- remove extra closing brackets

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM