views:

888

answers:

3

hello guys,

i wonder what i'm doing wrong?

    $('.player_audio').click(function() {
    if ($('.player_audio').paused == false) {
        $('.player_audio').pause();
        alert('music paused');
    } else {
        $('.player_audio').play();
        alert('music playing');
    }
});

i can't seem to start the audio track if i hit the "player_audio" tag.

<div class='thumb audio'><audio class='player_audio' src='$path/$value'></audio></div>

any idea what i'm doing wrong or what i have to do to get it working?

+5  A: 

Well, I'm not 100% sure, but I don't think jQuery extends/parses those functions and attributes (.paused, .pause(), .play()).

try to access those over the DOM element, like

$('.player_audio').click(function() {
  if (this.paused == false) {
      this.pause();
      alert('music paused');
  } else {
      this.play();
      alert('music playing');
  }
});
jAndy
any idea why a simple mp3 in my audio_player won't work in firefox 3.6?? it just shows a black rectangle. chrome and safari do not have problems at all!
As MadBrain pointed out, Firefox doesn't like MP3s. Use Ogg Vorbis instead. Isn't standardization wonderful?
Darren Oster
A: 

Because Firefox does not support mp3 format. To make this work with Firefox, you should use the ogg format.

MadBrain
This should have been a comment to the post in questions, not a separate answer.
Darren Oster
A: 

I did it inside of a jQuery accordion.

$(function() {
        /*video controls*/
            $("#player_video").click(function() {
              if (this.paused == false) {
                  this.pause();
              }
            });
        /*end video controls*/

        var stop = false;
        $("#accordion h3").click(function(event) {
            if (stop) {
                event.stopImmediatePropagation();
                event.preventDefault();
                stop = false;
            }
            $("#player_video").click();
        });

    });
kelly