Search code examples
javascriptjqueryjplayer

Can't change song in jPlayer after setting media


I have some jQuery working that starts a jPlayer playing an MP3 as shown below

$("#jquery_jplayer_1").jPlayer({
        ready: function () { 
          $(this).jPlayer("setMedia", { 
            mp3: mp3_url

          });
          $(this).jPlayer("play", 0);
        },
        swfPath: "/js",
        supplied: "mp3",

      });

This works fine. But when I try to change the song to another mp3 I can't. I run the same function but with a different mp3_url to no avail. I know the function is being called and that the arguments are being passed correctly. It is getting inside the function (tested with alert();) but don't know why it won't change the song?

Any help would be much appreciated.

Thanks


Solution

  • I solved the problem. Thanks for help anyway.

    Here is the code

    function updatePlayer(name, artist, guid){
            var player = $("#jquery_jplayer_1");
    
            player.jPlayer({
            ready: function () { 
              $(this).jPlayer("setMedia", { 
                mp3: guid
    
              }); 
              $(this).jPlayer("play", 0);
            },
            swfPath: "/js",
            supplied: "mp3",
    
          }); 
          player.jPlayer("setMedia", { 
                mp3: guid
              }); 
          player.jPlayer("play", 0);
        }