Search code examples
javascriptjqueryjplayer

jQuery jPlayer change media not working


I am trying to change the song on jQuery, using the developers guide, i have come up with this function:

<script type="text/javascript">
$(document).ready(function(){
    $('.embedinfo').click(function() {
        $("#jquery_jplayer_1").jPlayer( "clearMedia" );
        $("#jquery_jplayer_1").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                mp3:"/audio/<?php echo $audioarray[0]['audio']; ?>"

            }).jPlayer("<?php if(empty($auto)){ echo "pause"; }     elseif($auto==1){ echo "play"; } ?>");
        },
        swfPath: "/js/Jplayer.swf",
        supplied: "mp3",
        wmode: "window",
        solution:"flash,html",
        volume:"1"
        });
    });

});

The setMedia function is actually identical to the function i use to set the music initially (which does work), however this function to change the music from a click is not working.

The clearMedia function is working, just the set isnt. Why is it not working?


Solution

  • I found a solution

    instead of using

    $("#jquery_jplayer_1").jPlayer( "clearMedia" );
    

    which removes the media, use

    $("#jquery_jplayer_1").jPlayer( "destroy" );
    

    which unbinds all instances of .jPlayer, allowing the media to be updated from scratch.