I want to make a VBScript to control Windows Media Player

Showing 1-8 of 8 messages
I want to make a VBScript to control Windows Media Player lmsb 12/2/09 4:29 PM
Hi all,
I'm able to control WMP through the shell but I think is not the cleanest
solution.
Can anybody help me on how to make the VBScript to use the WMP
Activex or COM automation?
I've found some reference about Player object and WMPLib but so far I've
been getting compile or run time errors.
the actions I want to do are:
1. Open the file I want to play
2. Start play
3. wait 10 seconds.
4. Pause/Stop play
5. wait 10 seconds.
6. return to step no. 2.

I would appreciate your help very much. Regards.
--
God grants us all at the cost of effort.

Re: I want to make a VBScript to control Windows Media Player Reventlov 12/3/09 1:51 PM
Il giorno Wed, 2 Dec 2009 16:29:06 -0800, =?Utf-8?B?bG1zYg==?=
<lm...@discussions.microsoft.com> ha scritto:

>Hi all,
>I'm able to control WMP through the shell but I think is not the cleanest
>solution.
>Can anybody help me on how to make the VBScript to use the WMP
>Activex or COM automation?
>I've found some reference about Player object and WMPLib but so far I've
>been getting compile or run time errors.
>the actions I want to do are:
>1. Open the file I want to play
>2. Start play
>3. wait 10 seconds.
>4. Pause/Stop play
>5. wait 10 seconds.
>6. return to step no. 2.

Start with this

Set Player = createobject("Wmplayer.OCX.7")
Player.url =  "C:\BOB.MP3"  
wscript.sleep 10000
msgbox "end"

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

Re: I want to make a VBScript to control Windows Media Player lmsb 12/4/09 9:52 AM
To Reventlov,
   Thanks very much!
It works great!   Now I have the control!    Thanks!!!

One question if I may... the key line is:

>Set Player = createobject("Wmplayer.OCX.7")
what is the number 7 for?

--
God grants us all at the cost of effort.


"Reventlov" wrote:

> .
>

Another Example mr_unreliable 12/4/09 10:02 AM
lmsb wrote:
> Can anybody help me on how to make the VBScript to use the WMP
> Activex or COM automation?

hi imsb,

This is a bit of an extension of the script already given,
with a couple of extra "bells-and-whistles":

--- <code> ---
' windows media player test script, jw 02Dec09

Dim oWMP : Set oWMP = CreateObject("WMPlayer.OCX.7")

   With oWMP  ' saves typing
     .settings.autoStart = True
     .settings.volume = 50  ' 0 - 100
     .settings.balance = 0  ' -100 to 100
     .settings.enableErrorDialogs = False
     .enableContextMenu = False
     .URL = "c:\windows\desktop\AlmaMater.mp3"
     WScript.Sleep(8000)  ' time to load and start playing
     .Controls.Pause()  ' stop
     WScript.Sleep(5000)
     .Controls.Play()  ' go again
     WScript.Sleep(5000)
   End With

MsgBox "if WMP is still playing, clicking OK will end it", _
     vbInformation, "WMP Demo finished"

' note: With WMP running, and no set = nothing or quit
'   statement, then the script will not end until the
'   mp3 stops playing, and maybe not even then.  If you
'   want to be SURE, then look to catch some event fired
'   when the music ends.  I suggest the "EndOfStream"
'   event, but confess that I haven't tried it...
Set oWMP = nothing
WScript.Quit
--- </code> ---

It should be noted that there are TWO WMP controls,
at least on my (win98) system.

An "old" wmp, found in msdxm.ocx with a progid of:

   "MediaPlayer.MediaPlayer.1"

And a "new" wmp, found in wmp.dll, with a progid of:

   "WMPlayer.OCX.7"

Apparently the "left-over" WMP control is associated with
an older version of wmp, and was not de-installed when the
newer version came out.

cheers, jw
____________________________________________________________

You got questions?  WE GOT ANSWERS!!!  ..(but, no guarantee
    the answers will be applicable to the questions)

RE: Another Example lmsb 12/4/09 11:36 AM
Thanks very much. Mr. Unreliable!

I will try the code!
--
lmsb (Tijuana, Mexico)


God grants us all at the cost of effort.


"mr_unreliable" wrote:

> .
>

Re: I want to make a VBScript to control Windows Media Player Reventlov 12/4/09 1:53 PM
Il giorno Fri, 4 Dec 2009 09:52:01 -0800, =?Utf-8?B?bG1zYg==?=
<lm...@discussions.microsoft.com> ha scritto:

>To Reventlov,


>   Thanks very much!
>It works great!   Now I have the control!    Thanks!!!
>
>One question if I may... the key line is:
>>Set Player = createobject("Wmplayer.OCX.7")
>what is the number 7 for?

I found the name "wmplayer.ocx.7" in the registry. From a certain version of MediaPlayer
Microsoft provided this new version of the activeX component.

I found some information on how to use this com object in a file called wmpsdk.chm in a cd
shipped together with a book about MediaPlayer.
I borrowed the book from  the public library. It did not tell much about programming. Only
about deploying, skins  and custom installation of MediaPlayer.
But in the cd there was some other stuff.
Maybe you can find this file in ms site.
Dated 24 june 2000, it's a 1,02 Mb file.

Giovanni.

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

Re: Another Example Reventlov 12/4/09 2:00 PM
Il giorno Fri, 04 Dec 2009 13:02:45 -0500, mr_unreliable
<kindlyReply...@notmail.com> ha scritto:

>lmsb wrote:
>> Can anybody help me on how to make the VBScript to use the WMP
>> Activex or COM automation?

>It should be noted that there are TWO WMP controls,


>Apparently the "left-over" WMP control is associated with
>an older version of wmp, and was not de-installed when the
>newer version came out.

You are right.
wmpsdk.chm says the old control is still shipped with the new version of the ocx:

What's New
Three major changes have been made in the Windows Media Player control since the last
version.

The control has a new CLSID. It is 6BF52A52-394A-11D3-B153-00C04F79FAA6. The old control
is still shipped with this version to ensure that previous Web pages function correctly.
But if you want to take advantage of the new functionality of the control for this
version, you must change your CLSID.

The control has been split into subcontrols, including Controls, Settings, and Network.
Methods, properties, and events that are attached to the main control are documented under
the Player object. See the Control Reference for more information. Methods and properties
of the subcontrols are accessed through the player. For example, to use the bandWidth
property of the Network object, you must type:
player.Network.bandWidth

The following methods and properties are no longer supported in this version of the
Windows Media Player control:
AboutBox [....................]


--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

Re: I want to make a VBScript to control Windows Media Player mr_unreliable 12/4/09 6:00 PM
lmsb wrote:
> One question if I may... the key line is:
>> Set Player = createobject("Wmplayer.OCX.7")
> what is the number 7 for?

hi lmsb,

The number "7" in the progid is just a version number.

Most likely, you will find the "generic" progid in
your registry, which is "WMPlayer.OCX".  You could
use that in your script.  Part of the "generic" entry
is the "CurVer" (current version) key, which on my
system is "WMPlayer.OCX.7", i.e., version 7.  And so,
if you use the generic progid or the version-specific
progid, you get the same actx object (at least on my
system.

However, if ms comes out with a newer version, and
especially if the new version has different methods
and properties, then the version number WILL make
a difference.

cheers, jw
____________________________________________________________

You got questions?  WE GOT ANSWERS!!!  ..(but, no guarantee
    the answers will be applicable to the questions)