2016-02-27 47 views
1

我想要一個vbs腳本來請求YouTube視頻的網址並播放音頻。我有這個迄今爲止用Vbscript提取或播放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

嘗試這樣:

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 
'*********************************************************** 
+0

如果我把一個新的地址,它會播放不同的視頻。 –

+0

@AlienVilliger給我這個新的地址與你一起測試 – Hackoo

+0

https://www.youtube.com/watch?v=y8Kyi0WNg40 –