如何停止HTML5音频标签播放的音频

时间:2010-08-25 14:34:34

标签: javascript audio html5

我是HTML5新手,我正在探索HTML5功能。在那里,我遇到了音频标签 我用它编写代码来播放声音文件。
我对这个标签有一个问题。单击按钮时,我想更改停止前一个声音文件的声音文件 我搜索了很多但没有找到任何东西。 请帮我停止音频标签播放的声音。 这是我的代码;

  try
  {
       if(MyAudio != undefined)
       {
          MyAudio = null;
       }
       MyAudio = new Audio("filename");
       MyAudio.play();
  }
  catch(v)
  {
    //alert(v.message);
  }

2 个答案:

答案 0 :(得分:12)

试试这个:

  try
  {
       if(MyAudio != undefined)
       {
          MyAudio.pause();
       }
       MyAudio = new Audio("filename");
       MyAudio.play();
  }
  catch(v)
  {
    //alert(v.message);
  }

答案 1 :(得分:1)

如本cuestión所述:HTML5 Audio stop function,更好的解决方案可能是:

Dim wb as Workbook
Dim wb1 As Workbook, wb2 As Workbook
Dim ws  as Worksheet, ws1 As Worksheet, ws2 As Worksheet
Dim Lst As Long,
Dim r1, r2 As Range

Set wb = ThisWorkbook
Set wb1 = Workbooks.Open("Sheets("x").Range("A4").Value")
Set wb2 = Workbooks.Open("Sheets("x").Range("A5").Value")
With wb2
Call Wbkunprtect()