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... :(