0

Using the .NET Windows Media Player library, I have been able to obtain and alter various file properties (like user rating) for Windows Media Player programmatically. I wish to use the same library to control (play, stop, next, etc.) a Windows Media Player instance through a Player.openPlayer(url) call. In theory, this should be very possible through the Player.controls object, but none of the controls are available when I go to access them. Virtually all of the Player properties/methods/events are available to me except the controls object. Here is some sample code to illustrate what I've tried:

import clr
clr.AddReferenceToFile( "Interop.WMPLib.dll" )
from Interop.WMPLib import WindowsMediaPlayerClass
wmp = WindowsMediaPlayerClass()
wmp.openPlayer(r"C:\Users\Public\Music\Sample Music\Kalimba.mp3")

This works fine, but when I do the following:

print wmp.controls.isAvailable("play").ToString()
print wmp.controls.isAvailable("pause").ToString()
print wmp.controls.isAvailable("stop").ToString()
...

I get false for each control. Why are these controls not available to my (simple) application? Am I perhaps going about this the wrong way? I am using WMP 12, so it should be more than compatible. I would really prefer not to use another API, but I'm willing to try anything at this point.

Here is the documentation for reference: http://msdn.microsoft.com/en-us/library/dd564034%28v=vs.85%29.aspx

Edit: The quick fix is holding for now, but I still haven't found an actual solution yet.

covertCoder
  • 416
  • 3
  • 10
  • Is the question unclear at all? – covertCoder Apr 13 '12 at 13:44
  • No, but it's requires a pretty rare intersection of knowledge - you may be the first person ever to use IronPython to control WMP. :) What happens if you ignore `isAvailable` and just call `play()`? – Jeff Hardy Apr 16 '12 at 22:39
  • Nothing happens, same with all of the other control functions. The other functions do not return errors, but they do not perform their intended functionality either. My current quickfix is to call Player.openPlayer everytime I want to open a new playlist/media file, but this often leaves the WMP instance blinking or worst case forces focus onto it from whatever else I'm doing. – covertCoder Apr 17 '12 at 13:11

1 Answers1

0

try

print wmp.controls.get_isAvailable("play");
print wmp.controls.get_isAvailable("stop");
etc.

but keep in mind that those controls will be unavailable until you load a file into said WMP control.

firstly set wmp.URL to a path of the file you want to play, then, when it's done loading simply call wmp.controls.play();. You can listen for a OpenStateChange event to make sure if it's loaded.

marmulin
  • 61
  • 4
  • The thing is that wmp.controls.play() does not work no matter how I load up the wmp instance. I've tried wmp.URL, wmp.launchURL, wmp.openPlayer, etc. but wmp.controls.() still does nothing at all. Also, wmp.controls.get_isAvailable("control") returns an error, probably because the correct function is wmp.controls.isAvailable("control"), but then again I haven't been able to get either to work anyways. I make sure it's loaded before calling these controls, but OpenStateChange also never fires so... – covertCoder Apr 18 '12 at 13:30
  • Have you tried listening to `Error`, `MediaError` or `StatusChange` events? Does any event fire? They might help trace the error. Also isn't the player itself a `WindowsMediaPlayer` class (without the 'class' suffix)? – marmulin Apr 19 '12 at 10:52
  • From my understanding, WindowsMediaPlayer is the abstract class and WindowsMediaPlayerClass (known in the documentation as Player) is the actual API. Keep in mind this API is for scripting, and is not necessarily the same as the other WMP APIs. I have tried listening for the aforementioned events, but none of them fire when I use the player manually or programmatically. Sufficed to say, the documentation is a little confusing on what can and cannot be done. – covertCoder Apr 23 '12 at 14:28