Search code examples
javascriptjqueryjquery-pluginsjplayer

Is there a way to change Jquery plugin options with a click of a button?


I am using the Jplayer query plugin as an audio player on mysite. While I manage to set the options of the plugin through this:

$(document).ready(function(){

$("#jquery_jplayer_1").jPlayer({
    ready: function () {
        $(this).jPlayer("setMedia", {
            title: MediaTitle,
            mp3: MediaURL
        });
    },
    remainingDuration: true,
    defaultPlaybackRate: 1,  /* <-- I'd like to change the playback rate 
                                    when I click a button */
    toggleDuration: true
});
});

my goal is to assign a button to control the playback rate so when for example I press "speed" button the deafultPlaybackRate would go from 1 to 1.5 for example.

I'm thinking approaching this is by using the .click mouse event.

For example:

   <script type="text/javascript">
   $( ".speeder" ).click(function() {
       /*make the defaultPlaybackRate go from 1 to 1.5 */
    });
   </script> 

Am I on the right path? is it even possible to change global jquery plugin settings through events like a mouse click on a button?


Solution

  • Check out the documentation here:

    <script type="text/javascript">
       $( ".speeder" ).click(function() {
           $("#jquery_jplayer_1").jPlayer("option","playbackRate", "1.5"); // or
           //$("#jquery_jplayer_1").jPlayer("option",{playbackRate : 1.5});
        });
    </script>