How to listen to windows events in C#?
Asked Answered
W

2

6

I'm developing an lyrics related application and I need to listen to Windows Media Player Events. I watched windows events in "Accessible event watcher" and I found out that there's some events that WMP sends whenever it's state or current position changes. I searched and found this article on MSDN a How to set a Windows hook in Visual C# .NET but I couldn't make it work.

How can I listen to that events from my C# application or any suggestions on using other methods to get current song and WMP playing status?\

Thank You

Wellchosen answered 8/9, 2012 at 13:57 Comment(0)
N
3

This article describes how to get the events using the AxWindowsMediaPlayer which is the underlying root of the windows media player system. You will see that the various state change events can be picked up normally.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd562388(v=vs.85).aspx

You should be able to get a running instance from the windows ROT (Running objects table)?

http://www.darinhiggins.com/the-running-instance-of-windows-media-player/

Edit:

This is another way...

http://www.darinhiggins.com/gaining-access-to-a-running-instance-of-windows-media-player-in-vb-net/

Naker answered 8/9, 2012 at 14:7 Comment(5)
Thanks Visual Micro, I believe this will create a new instance of WMP control on the form, but I need to access the own WMP of the windows not creating a new one.Wellchosen
Is there any way to access the main WMP instance of the system from the ActiveX?Wellchosen
I've checked out that link you've sent. I was new to ROT, Its exactly what I want. but it doesn't work with Windows Media Player. I have a trouble with WMP's progId. I've tested the GetActiveObjects (System.Runtime.InteropServices.Marshal.GetActiveObject) with some other applications like Word2010 and it worked with this progId 'Word.Application'. How can I get progId for Windows Media Player?Wellchosen
That sounds a bit of a pain. I've seen a few possibilities but have extended the answer above with something interesting. I hope :)Naker
Thank you. I've checked it out a little. I think that's the solution:)Wellchosen
H
0

Does this help you? http://forums.msdn.microsoft.com/en-US/clr/thread/dbd43d7e-f3a6-4087-be06-df17e76b635d . There's also this post here Getting windows media player currently playing song that may answer your questions.

Hexagram answered 8/9, 2012 at 14:1 Comment(1)
I checked out the articles you suggested, but they can be used when using the WMP control on windows forms, but I need to get current media and state of the song that user is playing in the own WMP of windows.Wellchosen

© 2022 - 2024 — McMap. All rights reserved.