0

I'm trying to use a jPlayer to trigger the player in my template. I need to pass a value to the mp3 option but I don't know how to set mp3 in setMedia to music .

$(document).ready(function(){
  var music = $(".album-playlist li").first().find("input").val();
  $("#jquery_jplayer_1").jPlayer({
    ready: function () {
      $(this).jPlayer("setMedia", {
        mp3: music,
      }).jPlayer("");
    },
    swfPath: "http://mysite.com/wp-content/themes/beta/libs",
    supplied: "mp3"
  });
});    
Pollux Khafra
  • 862
  • 5
  • 17
  • 32

2 Answers2

0
$(document).ready(function(){
  var music = $(".album-playlist li").first().find("input").val();
  $("#jquery_jplayer_1").jPlayer({
    ready: function () {
      $(this).jPlayer("setMedia", { mp3 : music }).jPlayer("");
    },
    swfPath: "http://mysite.com/wp-content/themes/beta/libs",
    supplied: "mp3"
  });
});

I moved the music variable to a place it can be defined easier, also removed the dollar sign ($) from music variable you had in your passing values.

If you're curious what music currently holds in it, you can easily find out by inserting alert(music); right after var music. Example:

var music = $(".album-playlist li").first().find("input").val();
alert(music);
Bill Effin Murray
  • 426
  • 1
  • 5
  • 13
  • the alert shows the proper value but it isn't echoing that value after mp3: – Pollux Khafra Aug 31 '12 at 22:07
  • My mistake then, I was under the impression you wanted to know the value. Create a
    and use CSS to place it where you want. Then in the code you would use $("#whateveryouwant").html(music); That will set the inner HTML of the div to the value
    – Bill Effin Murray Aug 31 '12 at 22:13
0

Edit: Your question was about how to print a variable, but it seems that you actually want to figure out how to setMedia of a jPlayer

Check out this link http://www.jplayer.org/latest/developer-guide/#jPlayer-setMedia

$("#jquery_jplayer_1").jPlayer( {
  ready: function() {
    $(this).jPlayer( "setMedia", {
      mp3: "yourpath/movie.mp3"
    });
  },
  supplied: "mp3"
);

In your case all you have to do is move $music to the right scope. Like so:

$(document).ready(function(){
    var music = $(".album-playlist li").first().find("input").val();
    $("#jquery_jplayer_1").jPlayer( {
      ready: function() {
        $(this).jPlayer( "setMedia", {
          mp3: music
        });
      },
      supplied: "mp3"
    );
    $("#jquery_jplayer_1").append("Mp3: " + music);
});
Nate-Wilkins
  • 5,364
  • 4
  • 46
  • 61