How to stop audio played by audio tag of HTML5

前端 未结 2 1740
既然无缘
既然无缘 2021-02-13 04:16

I am new to HTML5 and I am exploring HTML5 features. There I came across audio tag.
I written code with it to play sound files.
I am having one problem with this tag. O

相关标签:
2条回答
  • 2021-02-13 04:30

    As commented in this cuestión: HTML5 Audio stop function, a better solution could be:

    var sound = document.getElementById("audio");
    sound.pause();
    sound.currentTime = 0;
    
    0 讨论(0)
  • 2021-02-13 04:43

    Try this:

      try
      {
           if(MyAudio != undefined)
           {
              MyAudio.pause();
           }
           MyAudio = new Audio("filename");
           MyAudio.play();
      }
      catch(v)
      {
        //alert(v.message);
      }
    
    0 讨论(0)
提交回复
热议问题