html5 audio player - jquery toggle click play/pause?

前端 未结 15 2255
南笙
南笙 2020-11-28 06:24

i wonder what i\'m doing wrong?

    $(\'.player_audio\').click(function() {
    if ($(\'.player_audio\').paused == false) {
        $(\'.player_audio\').paus         


        
相关标签:
15条回答
  • 2020-11-28 06:33

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

    0 讨论(0)
  • 2020-11-28 06:33

    Here is my solution using jQuery

    <script type="text/javascript">
        $('#mtoogle').toggle(
            function () {
                document.getElementById('playTune').pause();
            },
            function () {
                document.getElementById('playTune').play();
            }
        );
    </script>
    

    And the working demo

    http://demo.ftutorials.com/html5-audio/

    0 讨论(0)
  • 2020-11-28 06:35

    Simply Use

    $('audio').trigger('pause');
    
    0 讨论(0)
  • 2020-11-28 06:41

    This thread was quite helpful. The jQuery selector need to be told which of the selected elements the following code applies to. The easiest way is to append a

        [0]
    

    such as

        $(".test")[0].play();
    
    0 讨论(0)
  • 2020-11-28 06:42

    Here is my solution (if you want to click another element on the page):

    $("#button").click(function() {
            var bool = $("#player").prop("muted");
            $("#player").prop("muted",!bool);
            if (bool) {
                $("#player").prop("currentTime",0);
            }
    });
    
    0 讨论(0)
  • 2020-11-28 06:47

    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');
      }
    });
    
    0 讨论(0)
提交回复
热议问题