如何使用vbscript随机播放目录中的声音文件
How to randomly play a sound file from a directory using vbscript
我正在尝试 windows 运行 这个 vbs 文件放在 windows 的开头,这样计算机就可以用我制作并另存为的短语来问候我wav 文件。
我已经有一个 vbs 文件,它可以播放一个声音文件,但我希望它从特定目录中随机选择一个,这样它就不会老了,一遍又一遍地听到同样的东西,再加上一个惊喜因素,因为我不知道每次启动计算机时它会使用哪个。
Dim oPlayer
Set oPlayer = CreateObject("WMPlayer.OCX")
' Play audio
oPlayer.URL = "C:\Users\david\OneDrive\Desktop\GLaDOS
wav\Edited\hello_david_youre_back_i_see.wav"
oPlayer.controls.play
While oPlayer.playState <> 1 ' 1 = Stopped
WScript.Sleep 100
Wend
' Release the audio file
oPlayer.close
提前感谢您的帮助。
Option Explicit
Dim oFolderItems
Dim oFolderItem
Dim aFiles
Set oFolderItems = CreateObject("Shell.Application").NameSpace("C:\Users\david\OneDrive\Desktop\GLaDOSwav\Edited").Items
oFolderItems.Filter 64 + 128, "*.wav"
With CreateObject("Scripting.Dictionary")
For Each oFolderItem In oFolderItems
.Item(.Count) = oFolderItem.Path
Next
aFiles = .Items
End With
Randomize
With CreateObject("WMPlayer.OCX")
.URL = aFiles(Int(Rnd * UBound(aFiles) + 1))
.controls.play
Do While .playState <> 1
WScript.Sleep 100
Loop
.close
End With
我正在尝试 windows 运行 这个 vbs 文件放在 windows 的开头,这样计算机就可以用我制作并另存为的短语来问候我wav 文件。
我已经有一个 vbs 文件,它可以播放一个声音文件,但我希望它从特定目录中随机选择一个,这样它就不会老了,一遍又一遍地听到同样的东西,再加上一个惊喜因素,因为我不知道每次启动计算机时它会使用哪个。
Dim oPlayer
Set oPlayer = CreateObject("WMPlayer.OCX")
' Play audio
oPlayer.URL = "C:\Users\david\OneDrive\Desktop\GLaDOS
wav\Edited\hello_david_youre_back_i_see.wav"
oPlayer.controls.play
While oPlayer.playState <> 1 ' 1 = Stopped
WScript.Sleep 100
Wend
' Release the audio file
oPlayer.close
提前感谢您的帮助。
Option Explicit
Dim oFolderItems
Dim oFolderItem
Dim aFiles
Set oFolderItems = CreateObject("Shell.Application").NameSpace("C:\Users\david\OneDrive\Desktop\GLaDOSwav\Edited").Items
oFolderItems.Filter 64 + 128, "*.wav"
With CreateObject("Scripting.Dictionary")
For Each oFolderItem In oFolderItems
.Item(.Count) = oFolderItem.Path
Next
aFiles = .Items
End With
Randomize
With CreateObject("WMPlayer.OCX")
.URL = aFiles(Int(Rnd * UBound(aFiles) + 1))
.controls.play
Do While .playState <> 1
WScript.Sleep 100
Loop
.close
End With