I'm not sure if this is the correct forum for this question, but I
couldn't find anywhere else pertinent either, so here goes.

I'm trying to get the currently playing track name from Windows Media
Player 7 (I assume 8 has the same basic structure).  I have code that
can get it from WMP 6 and below, but MS changed the way WMP displays
track names for version 7.

This is the code for getting it from ver 6  (FindWindow and
GetWindowText are from user32.dll):

IntPtr hwindow = FindWindow("Media Player 2", null);
if (hwindow != IntPtr.Zero)
{
        // let's go find the titlebar
        StringBuilder this_title = new StringBuilder(2048, 2048);
        GetWindowText(hwindow,this_title, 2048);

        string name = this_title.ToString();

        int ndx = name.IndexOf(".mp3");
        // is it actually playing an mp3?
        if(ndx != -1)
                Song = name.Substring(0, ndx);
        else
                Song = "";
}

Basically it gets a handle to the WMP window then gets the title bar
text and parses it out.  This works for almost every other mp3 player
out there.   The problem is that MS changed things around for WMP7.  I
used Spy++ to examine WMP7 as it was playing a song, and I could not
find any reference to the track in any of the window class captions
associated with it.

So, is there some other way of getting the name of the currently playing
track, perhaps via some COM interop?

Thanks,

--Oren

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to