HELP- Trying to get jPlayer to use space bar as play/pause button.

634 views
Skip to first unread message

E-bot

unread,
Jun 21, 2012, 7:25:45 PM6/21/12
to jpl...@googlegroups.com
HI, I'm trying to get jPlayer to use the code that I came up with to use the space bar as a play/pause toggle button.  It works in jsfiddle, and you can see that here->  http://jsfiddle.net/Q4LMV/10197/  but it won't seem to work on my website here->  http://tamarackslumberjacks.com/ .  Any ideas??   

E-bot

unread,
Jul 15, 2012, 12:17:51 AM7/15/12
to jpl...@googlegroups.com
Has anyone tried to use the space-bar to play/pause before??

Mark Panaghiston

unread,
Jul 16, 2012, 11:30:42 AM7/16/12
to jpl...@googlegroups.com
Your fiddle does not work. The code:
   event.preventDefault();
Should be:
   e.preventDefault();
Since the function constructor looks like:
   window.onkeydown=function(e){

Plus, I'd need to double check that preventDefault() is a DOM command. I only use it through jQuery.

You should also consider using jQuery to perform the key function. The code looks like:

    $(document.documentElement).keydown(function(event) {
        event.preventDefault();
        if(event.which === 32) {
            if($("#jquery_jplayer_1").data("jPlayer").status.paused) {
               $("#jquery_jplayer_1").jPlayer("play");
            } else {
               $("#jquery_jplayer_1").jPlayer("pause");
            }
        }
    });

E-bot

unread,
Jul 20, 2012, 3:02:15 AM7/20/12
to jpl...@googlegroups.com
Hi Mark,
It doesn't appear that the jQuery code work either.  I assume that I can put the code in the head section of the html file I want it to work on.

Mark Panaghiston

unread,
Jul 20, 2012, 7:56:07 AM7/20/12
to jpl...@googlegroups.com

E-bot

unread,
Jul 20, 2012, 5:17:13 PM7/20/12
to jpl...@googlegroups.com
The fiddle works for me too, but I can't find a place in the website to drop the code into and replicate the same result as  the fiddle.  I've tried putting it in the header between scripts tags, and appending the function into js files.  Not sure what else to try.

Mark Panaghiston

unread,
Jul 23, 2012, 9:55:39 AM7/23/12
to jpl...@googlegroups.com
You have included jQuery twice. This corrupts jQuery.
Reply all
Reply to author
Forward
0 new messages