【问题标题】:Extract or play youtube audio with Vbscript使用 Vbscript 提取或播放 youtube 音频
【发布时间】:2016-02-27 05:12:51
【问题描述】:

我正在尝试获取一个 vbs 脚本来请求 youtube 视频的 url 并播放音频。到目前为止我有这个

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

【问题讨论】:

    标签: audio vbscript youtube


    【解决方案1】:

    试试这样的:

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

    【讨论】:

    • 如果我输入一个新地址,它会播放不同的视频。
    • @AlienVilliger 给我这个新地址和你一起测试
    • 我不会停止播放音频。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2014-02-21
    • 2018-05-19
    • 2011-05-29
    • 2013-01-25
    • 2013-03-02
    • 2018-05-28
    相关资源
    最近更新 更多