gpt4 book ai didi

audio - 出现msgbox时,从VBScript中播放声音文件

转载 作者:行者123 更新时间:2023-12-02 22:21:00 26 4
gpt4 key购买 nike

出现某些msgbox时,我试图从VBScript中播放声音文件。唯一的问题是,我将把它发送到其他地方,接收它的人将没有与我要播放的音频文件相同的路径名。我当时正在考虑将所有要使用的声音文件与脚本放在同一文件夹中,然后发送该文件夹,但是我不知道如何确保声音文件能够播放。

因此,我想最大的问题是如何推广路径名,以便任何人都可以从任何计算机的脚本中听到文件。

到目前为止,这是我的代码:

    if intAnswer3 = vbyes then
strSoundFile = "C:\pathname"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True

最佳答案

假定您的脚本中有一个名为音乐的文件夹,因此您可以使用像这样的相对路径。/Music/Matrix.mp3

所以你可以这样尝试:

Option Explicit
Dim Msg,Question,PathSound
Msg = "Did you want to hear some music ?"
PathSound = "./Music/Matrix.mp3" 'Relative Path
Question = MsgBox(Msg,VbQuestion+VbYesNo,Msg)
If Question = VbYes Then
Call Play(PathSound)
Else
Wscript.Quit()
End If
'**********************************************************
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
'**********************************************************

如果您想在线播放音乐,则可以这样进行:
Option Explicit
Dim Msg,Question,PathSound
Msg = "Did you want to hear some music ?"
PathSound = "http://hackoo.alwaysdata.net/Matrix.mp3"
Question = MsgBox(Msg,VbQuestion+VbYesNo,Msg)
If Question = VbYes Then
Call Play(PathSound)
Else
Wscript.Quit()
End If
'**********************************************************
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
'**********************************************************

我希望这个答案可以帮助您完成主脚本;)

关于audio - 出现msgbox时,从VBScript中播放声音文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com