Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: VBS Pause/Resume music WMPlayer.OCX  (Read 16113 times)

0 Members and 1 Guest are viewing this topic.

Swollow

    Topic Starter


    Starter

    • Experience: Experienced
    • OS: Windows 7
    VBS Pause/Resume music WMPlayer.OCX
    « on: September 09, 2012, 01:04:50 PM »
    hey, I know how to play music in VBS like so:
    Code: [Select]
    Set wmp = CreateObject("WMPlayer.OCX")
    wmp.settings.autoStart = True
    wmp.settings.volume = 50
    wmp.URL = "Music.mp3"
    while wmp.Playstate <> 1
    WSH.Sleep 100
    wend
    but how would I pause/resume music?

    (I'm using Windows 7 FYI)

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: VBS Pause/Resume music WMPlayer.OCX
    « Reply #1 on: September 09, 2012, 03:36:07 PM »
    Script will play first 20 seconds of song, pause for 5 seconds and then resume playing the song. Change the timings as needed.

    Code: [Select]
    Set wmp = CreateObject("WMPlayer.OCX")

    wmp.settings.autoStart = True
    wmp.settings.volume = 50
    wmp.URL = "Music.mp3"
    PauseAndResume()

    While wmp.Playstate <> 1
      WScript.Sleep 100 
    Wend

    Function PauseAndResume()
      WScript.Sleep 20000
      wmp.controls.pause()
      WScript.Sleep 5000
      wmp.controls.play()
    End Function

    WSH was not defined. Changed to WScript.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Swollow

      Topic Starter


      Starter

      • Experience: Experienced
      • OS: Windows 7
      Re: VBS Pause/Resume music WMPlayer.OCX
      « Reply #2 on: September 09, 2012, 07:30:48 PM »
      How would I pause music that was playing from a different vbs script, like 1 file to play a song and 1 to pause it and 1 to resume it

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: VBS Pause/Resume music WMPlayer.OCX
      « Reply #3 on: September 10, 2012, 10:23:56 AM »
      You want two scripts to control the same object instance (WMP)? I think you would have to create an out-of-process COM object. Don't know if this would work, but it sure sounds promising.  ;)

      An alternative would be to run WMP in a window. While the media is playing, give the WMP window focus and you can use CTL-P to control pause/resume operations. See this post for ideas.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Swollow

        Topic Starter


        Starter

        • Experience: Experienced
        • OS: Windows 7
        Re: VBS Pause/Resume music WMPlayer.OCX
        « Reply #4 on: September 10, 2012, 04:11:42 PM »
        You want two scripts to control the same object instance (WMP)? I think you would have to create an out-of-process COM object. Don't know if this would work, but it sure sounds promising.  ;)

        An alternative would be to run WMP in a window. While the media is playing, give the WMP window focus and you can use CTL-P to control pause/resume operations. See this post for ideas.

         8)
        what I'm doing is programming MS-DOS Batch and occasionally using vbs files to do things batch can't so the second option isn't going to work, I'm not very familiar with vbs and don't know what an out of process COM object is, its rather hard to get batch to communicate with the vbs maybe an option would be to create a text document with the value of the time the music was at then kill the process and then restart the process later with the music starting at that point in time

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: VBS Pause/Resume music WMPlayer.OCX
        « Reply #5 on: September 11, 2012, 07:42:51 AM »
        I don't think this is going to happen. Giving focus to Win7 WMP from an external script for some reason does not work. I could only give focus from within the script that launched WMP. That would eliminate having seperate scripts for pause and resume.

        The Script Component also fizzled out. I could get the music to play but could not pause/resume it. The WMP object and the script run asynchronous, which explains the while/wend loop in your script and the sleep in my script. VBScript is single threaded, so interrupting the loop might not be possible.

        My suggestion is to manually start the music, and use CTL-P to toggle between pause and resume. Make sure the WMP window has focus when using CTL-P.

         8)

        To add insult to injury, I found that giving focus to WMP on WinXP works just fine.
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein

        Swollow

          Topic Starter


          Starter

          • Experience: Experienced
          • OS: Windows 7
          Re: VBS Pause/Resume music WMPlayer.OCX
          « Reply #6 on: September 11, 2012, 04:16:47 PM »
          alright thanks for trying though