简体   繁体   English

如何在HTML中使用VBScript播放WAV文件

[英]How to play WAV file using VBScript in HTML

How to play WAV file using VBScript in HTML ? 如何在HTML中使用VBScript播放WAV文件?

I have got following code but it is not working. 我有以下代码,但无法正常工作。

<script type="text/vbscript" language="VBScript"> 
   Dim strSoundFile, strCommand  
   strSoundFile = "C:\Sounds\Sound1.wav"
   Set objShell = CreateObject("Wscript.Shell")
   strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
   objShell.Run strCommand, 0, True
</script>

I found another code but it doesnt work as well if I use it in HTML page but it is working great in a *.VBS. 我找到了另一个代码,但是如果我在HTML页面中使用它,它也无法正常工作,但是在* .VBS中它的效果很好。

  Sub Play(SoundFile)
            Dim Sound
            Set Sound = CreateObject("WMPlayer.OCX")
            Sound.URL = SoundFile
            Sound.settings.volume = 100
            Sound.Controls.play
            do while Sound.currentmedia.duration = 0
                wscript.sleep 100
            loop
            wscript.sleep(int(Sound.currentmedia.duration)+1)*1000
            End Sub

I have found this link https://support.microsoft.com/es-es/kb/279022 but I am not shure if it is a correct way... 我已找到此链接https://support.microsoft.com/es-es/kb/279022,但我不确定这是否是正确的方法...

The way is working fine via in BODY tag is following 通过BODY标签的方式工作正常

<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="WindowsMediaPlayer" 
width="242" height="202" style="position:absolute; left:1;top:1;">
  <param name="URL" value="C:\Sound1.wav">
  <param name="autoStart" value="1">
</object>

Could it be done using this? 可以用这个做吗?

<script type="text/vbscript" language="VBScript"> HERE </script>

I am using IE8 under MS Windows 7 Pro. 我在MS Windows 7 Pro下使用IE8。

Finally I could find correct approach to do what I need is described here 最后我能找到正确的方法做我需要的是描述在这里

Basically the idea is following 基本上这个想法是跟随

  1. We cannot use code above in the HTML instead we have to use embedded Windows Media Player object. 我们不能在HTML中使用上面的代码,而必须使用嵌入式Windows Media Player对象。
  2. We can create any methods we need to manipulate that object in VBScript. 我们可以创建在VBScript中操作该对象所需的任何方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM