0

I have been using Applescript to control playback of Quicktime Player under OSX and are now trying to do the same on Windows 7 and Windows Media Player window.

All I need to do is,

  • Launch WMP and load audio file
  • Toggle playback
  • Skip forward or backwards x number of seconds.
  • Get its position in the audio file.
  • Jump playback to any position I choose.
  • Sub-Second positioning. (See EDIT below)

The SDK at the MSDN site seems to offer all that I need but my code below doesn't work.

Set oWmp = CreateObject("WMPlayer.OCX")

' Launches WMP window    
oWmp.openPlayer("F:\2014-04-27.mp3")

' This launches background process, don't want this...
'oWmp.url = "file:///F:/2014-04-27.mp3"

' Wait for file to load...
wscript.sleep 200

' Check the state of the player...
While oWmp.Playstate <> 3
    log "Waiting for player. Current state is: " & oWmp.Playstate
    WScript.Sleep 100 
Wend

oWmp.controls.pause()

wscript.sleep 2000

oWmp.controls.play()

The only thing that does work is openPlayer statement. Everything else executes but does not error or do anything. Playstate is always 0, even when I go to the WMP window and click on pause/play or stop. I am working on Windows 7 32bit with WMP12

I do not want to play audio in the background. I want to control playback in WMP window. Using .url = ... then the code works. This is running in the background though. See here for more.

Is the above at all with WMP? I'm happy to use VBS or JScript.


EDIT: After some more research, I found that Apple's iTunes has a decent scripting interface and it can do all that I listed above. But upon testing it I remembered that I need sub second positioning which iTunes COM interface does not provide... :(

  • Yes, the WMPlayer.OCX object is for scripting WMP. What's the output of your script and where exactly is it failing? – Tim De Baets Nov 18 '15 at 20:16
  • @TimDeBaets The only thing that does work is openPlayer statement. Everything else executes but does not error or do anything. I working on Windows7 with WMP12. Playstate is always 0, even when I go to the WMP window and click on pause/play or stop. – Dude named Ben Nov 20 '15 at 5:17
  • I've edited my question and it appears the code will work only for the WMP object in the background. It does NOT work for the WMP window. :( – Dude named Ben Nov 20 '15 at 5:41
0

openPlayer starts another instance of WMP, in full mode. All the other WMP calls in your script only affect the internal instance of WMP that was created by your call to CreateObject. That internal instance is invisible in this case, but can also be visible, like when the WMP control is embedded in a web page.

Interacting with the full mode WMP is called "remoting", see here for more info. But I'm afraid that it's not possible to do this from a script. You will need to write a special program in a language like C++.

0

Even though Tim answered the question as posted, I want to add this answer for future reference to anyone else trying to do the same thing.

As I mentioned, in my question's edit, Quicktime Player for Windows was close but not quite. So I kept searching and found a scripting plugin for the venerable old WinAmp audio player and it works great! I get millisecond positioning and everything else I need.

Only minor issue with it is that it's 32bit and running it in an Windows x64 environment means that I have to remember to use the right VBS engine, which is no big deal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.