Jump to content

Basic Windows Media Player question


 Share

Recommended Posts

Can someone please help me troubleshoot this basic script:

$oWM=ObjCreate("WMPlayer.OCX.7")
$oWM.OpenPlayer(@MyDocumentsDir & "\testMessage.wav")
Sleep(5000)
$oWM.Controls.pause()

My ultimate goal is to use AutoitX through another software program to control a WMP window that may be open in the background.  But the above script was written just to see if I could create the WMP object and control the playback.  The "OpenPlayer" method works fine and the player launches and starts playing.  But it just continues playing even after the script ends.  If I could get this simple script to work then I think I could

piece together my overall goal of controlling the WMP in the background while in another program such as Word.  I don't want to create my own embedded player and there are reasons too complicated to explain here why I have to do it this way with AutoitX.

If I could just get this simple script to work...... 

Link to comment
Share on other sites

Try something like this.

$wmp = ObjCreate("wmplayer.OCX")

$wmp.settings.autoStart = True
$wmp.settings.volume = 50
$wmp.URL = @MyDocumentsDir & "\testMessage.wav"

PauseAndResume()

While $wmp.Playstate <> 1
    Sleep(100)
WEnd

Func PauseAndResume()
    Sleep(20000)
    $wmp.controls.pause()
    ConsoleWrite("Paused" & @CRLF)
    Sleep(5000)
    $wmp.controls.play()
    ConsoleWrite("Playing" & @CRLF)
    Sleep(5000)
    $wmp.controls.stop()
    ConsoleWrite("Stopped" & @CRLF)
EndFunc

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Actually I tested my script using an MP3, I just changed it to his file name for convenience.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The reason this type of solution is insufficient is that it requires the script to stay running for the playback controls to work. Using the "open player" method in my test script is different because it launches the player that stays open even after the script ends. This implies that the player that launches is not connected anymore to the $oWM object because that is deleted when the script finishes. Try your test script using the openplayer method instead of the URL method and you'll see what I mean. It won't work.

The reason I need to attach to an existing WMP object is I cannot have an autoit executable running at all times. I need to jump in and pause/start an existing WMP object using AutoitX in another software program. So maybe a better way to have set this test snippet up would be to first open WMP manually and then run the following script with the WMP window minimized:

$oWM=ObjGet("","WMPlayer.OCX.7")

$oWM.Controls.pause()

Why won't this attach to the WMP object and allow me to control it? Getting either test to work would get me started in building the script. Sorry if I'm not doing a good job explaining this.

Link to comment
Share on other sites

Why do you need a script to start the media player if you aren't trying to control it while it's running? If all you want to do is start it and let it run on its own, use a batch file. You're not at all clear as to what you're trying to accomplish. First you're complaining that it won't stop after your script ends, now you're complaining that what I posted won't keep it running after the script ends.

Please make up your mind as to what it is you want.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I know what I want. I thought it would be easiest to make a simple script example that would demonstrate my problem.

I need a script to control the media player but it must be a separate script from the one that started it. So I need to attach to the object of the currently running windows media player. One script to pause it and another script to play it and a different script to rewind it five seconds. I have reasons for needing to do it this way that aren't worth explaining. Just know that this creates the need to attach to an existing WMP object.

The original simple test script demonstrated my inability to Connect to the media player object once it was launched with the open player method. My "complaining" that it wouldn't stop playing in the sample script means that the object that I created with the open player method was not $oWM and therefore I couldnt control it.

Like I said, maybe a simpler challenge would be to write an autoit script that could attach to an existing Windows media player window and control it even if it is minimized. Doing that would demonstrate the ability to connect to an existing WMP object. Once I know how to do that then I can do everything else that I need. I don't know how else to explain it but if you have more specific questions I can try to answer. I do appreciate you and others trying to help

Link to comment
Share on other sites

That is not what you said in your OP

 

My ultimate goal is to use AutoitX through another software program to control a WMP window that may be open in the background.

...

If I could get this simple script to work then I think I could piece together my overall goal of controlling the WMP in the background while in another program such as Word

I believe the the reason the original does not work is that "OpenPlayer" does return anything.  The URL method is what you want in that case. That avoids nothing trying to pause.  That approach solved the code you posted in your OP.  Stopping the AutoIt script and then restarting it and re-attaching to the object ... that is a different question. 

EDIT: I see you are trying ObjGet - but I think this may be the problem:

 

If you are already playing a file when AutoIt exits then I assume you lose the returned value of URL object method when you close the first Au3 script. That may be the challenge? 

I know you did not want to get into details but it would be very useful to know why you are trying to accomplish this to see if there is a better way ...

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

Why won't this attach to the WMP object and allow me to control it? Getting either test to work would get me started in building the script. Sorry if I'm not doing a good job explaining this.

Perhaps wmp does not support late binding.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

O.K.  I am trying to use WMP to play back a file that a client is listening to and transcribing in a Microsoft Word window.  So I wanted to have hotkey control to pause it when he gets behind in the transcription and rewind 5 seconds etc.  I cannot install any custom .exe's for this particular client.  Otherwise it would be a simple solution to embed my 

own WMP object and retain the object as long as the .exe was running.  But there is already a software that is running that has a scripting platform built into it where I can

pull in COM objects and work that way. I have already done this successfully with Word and Excel objects by using something similar to ObjGet("Word.Application").  And the existing software allows me to attach scripts/functions to keystrokes.  So, when a keystroke is pressed I would like to bind to the WMP Object and then play/pause/rewind it without leaving the window where the individual is doing the transcribing.  This is why it has to be in the background.  Otherwise I'd use Winactivate("Windows Media Player") and then ControlSend("^p") etc to do it. 

So, it boils down to being able to attach to existing WMP objects much like we do for Excel/Word to manipulate existing windows in the background.  I knew if I could do it in a simple Autoit script then I could do it in the other platform

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...