我正在尝试使用vbs脚本来查询YouTube视频的网址并播放音频。到目前为止我有这个
Option Explicit
Dim Msg,Question,PathSound,URL
URL = InputBox("What url would you like to play from?")
PathSound = "URL"
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
'**********************************************************
答案 0 :(得分:0)
尝试这样的事情:
Option Explicit
Dim Msg,Question,URL,Title
Title = "Extract or play youtube audio with Vbscript by Hackoo 2016"
Msg = "Did you want to continue with this script to play music ? or stop music and quit this script ?"
Question = MsgBox(Msg,VbQuestion+VbYesNo,Title)
If Question = VbYes Then
URL = InputBox("What url would you like to play from ?" , "Play Sound from internet",_
"https://www.youtube.com/watch?v=4Aa9GwWaRv0")
'http://www.chocradios.ch/djbuzzradio_windows.mp3.asx
If URL = "" Then Wscript.Quit()
If Instr(URL,"youtube") > 0 Then
Call Play_Youtube(URL)
Else
Call Play(URL)
End If
Else
Call Kill("iexplore.exe")
Call Kill("Wscript.exe")
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
'**********************************************************
Sub Play_Youtube(URL)
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate(URL)
ie.Visible=false
DO WHILE ie.busy
LOOP
End Sub
'**********************************************************
Sub Kill(Process)
Dim Command,Ws,Execution
Set Ws = CreateObject("Wscript.Shell")
Command = "cmd /c Taskkill /F /IM "& Process &""
Execution = Ws.Run(Command,0,True)
End Sub
'***********************************************************