4

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

JackMahoney
  • 3,423
  • 7
  • 32
  • 50

2 Answers2

4

Just like this:

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

Jplayer('destroy') documentation

Kevin Beal
  • 10,500
  • 12
  • 66
  • 92
Shoaib Ahmed
  • 747
  • 12
  • 28
2

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);
    }
JackMahoney
  • 3,423
  • 7
  • 32
  • 50