locked
Query WMP 12 Library data? RRS feed

  • Question

  • Is there a way to query the Windows Media Player 12 Library? 

    I’d like to use Access 2010 to query and print reports of Windows Media Player 12 Library data.

    Wednesday, May 23, 2012 1:44 AM

Answers

  • Hi,

    I'm not sure you want to get all the items (audio, video, pictures...). But to have smth to start with let's see this code sample. We'll get all audio items in the WMP library and their names, URLs and Authors:

    Public Sub testWMP()
    Dim wmp As WMPLib.WindowsMediaPlayer, i%
        Set wmp = Forms("form1").Controls("wmp1").Object
        With wmp.mediaCollection.getByAttribute("MediaType", "Audio")
            For i = 0 To .Count - 1
                Debug.Print "Name: " & .Item(i).Name & " URL: " & .Item(i).sourceURL & " Author: " & .Item(i).getItemInfo("Author")
            Next i
        End With
    End Sub

    So everything looks easy. One thing I don't like is that we should create an ActiveX control. It would be great if there is an ability to query WMP Library directly. Note: I don't say there is no such way. ;)

    In the above sample:

    .getByAttribute allows to receive items which belong to a certain category. For such a purpose we use an attribute "MediaType". You can also use any other attribute you like. The whole list of them is available here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd562330(v=vs.85).aspx

    .getByAttribute (as well as .getAll) returns a Playlist collection. Each member (item) is a Media object which represents a certain file - a memeber of the WMP Library. It also has attributes and you can read their values respectively as shown above.

    The result of this sub for a clean WMP setup is:

    Name: Symphony No. 9 (Scherzo) URL: C:\Documents and Settings\All Users\Documents\My Music\Sample Music\Beethoven's Symphony No. 9 (Scherzo).wma Author: Ludwig van Beethoven, composer. Seattle Symphony. Gerard Schwarz, director
    Name: "Highway Blues" URL: C:\Documents and Settings\All Users\Documents\My Music\Sample Music\New Stories (Highway Blues).wma Author: Marc Seales, composer. New Stories. Ernie Watts, saxophone.

    I think its enough to have a quick start. To create a table you should walk through the results in a loop and instead of debug.print - insert records in a table. Either via CurrentDb.Execute "INSERT INTO...  or a recordset. Whatever you like more. Of course, if you have any further questions, post them.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru

    • Marked as answer by DriveEV Thursday, May 24, 2012 12:41 PM
    Thursday, May 24, 2012 9:00 AM

All replies

  • I can think of a way:

    Set a reference (Tools > References) to Windows Media Player.

    Create a new blank form, design it, drop down the Controls list, choose ActiveX Controls and select Windows Media Player. I renamed the control wmp.

    Add a button. In its click event write:

        Dim oWmp As wmpLib.WindowsMediaPlayer
        Set oWmp = Me.wmp.Object

    You now have an object representing the wmp. You can peruse it using the debugger, and the Object Browser. The WMP SDK is documented on MSDN.

    This would certainly require robust programming skills, but it is possible.


    -Tom. Microsoft Access MVP

    Wednesday, May 23, 2012 2:51 AM
  • Hi Tom,

    Thanks for the quick reply.  I see two “Windows Media Player” references.

    The first is msdxm.tlb and the second is wmp.dll

    Which did you choose?

    Wednesday, May 23, 2012 3:11 AM
  • The second one.

    -Tom. Microsoft Access MVP

    Wednesday, May 23, 2012 3:19 AM
  • My goal is not to control WMP through Access but to query the WMP Library.

    Like:

    SELECT ?????????.*
    FROM ?????????;

    Wednesday, May 23, 2012 3:20 AM
  • One step at a time. Using the object model you can access the Library. You can then save the library items to a table, and then query the table.


    -Tom. Microsoft Access MVP

    Wednesday, May 23, 2012 4:01 AM
  • Can anyone point me in the right direction to get example VBA code that utilizes the WMP object model and method MediaCollection.getall to create a table in Access of all media items in the library?

    The getAll method retrieves a playlist containing all media items in the library.

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

    If I come up with the code myself I will post here to save others time.

    Wednesday, May 23, 2012 2:16 PM
  • Hi,

    I'm not sure you want to get all the items (audio, video, pictures...). But to have smth to start with let's see this code sample. We'll get all audio items in the WMP library and their names, URLs and Authors:

    Public Sub testWMP()
    Dim wmp As WMPLib.WindowsMediaPlayer, i%
        Set wmp = Forms("form1").Controls("wmp1").Object
        With wmp.mediaCollection.getByAttribute("MediaType", "Audio")
            For i = 0 To .Count - 1
                Debug.Print "Name: " & .Item(i).Name & " URL: " & .Item(i).sourceURL & " Author: " & .Item(i).getItemInfo("Author")
            Next i
        End With
    End Sub

    So everything looks easy. One thing I don't like is that we should create an ActiveX control. It would be great if there is an ability to query WMP Library directly. Note: I don't say there is no such way. ;)

    In the above sample:

    .getByAttribute allows to receive items which belong to a certain category. For such a purpose we use an attribute "MediaType". You can also use any other attribute you like. The whole list of them is available here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd562330(v=vs.85).aspx

    .getByAttribute (as well as .getAll) returns a Playlist collection. Each member (item) is a Media object which represents a certain file - a memeber of the WMP Library. It also has attributes and you can read their values respectively as shown above.

    The result of this sub for a clean WMP setup is:

    Name: Symphony No. 9 (Scherzo) URL: C:\Documents and Settings\All Users\Documents\My Music\Sample Music\Beethoven's Symphony No. 9 (Scherzo).wma Author: Ludwig van Beethoven, composer. Seattle Symphony. Gerard Schwarz, director
    Name: "Highway Blues" URL: C:\Documents and Settings\All Users\Documents\My Music\Sample Music\New Stories (Highway Blues).wma Author: Marc Seales, composer. New Stories. Ernie Watts, saxophone.

    I think its enough to have a quick start. To create a table you should walk through the results in a loop and instead of debug.print - insert records in a table. Either via CurrentDb.Execute "INSERT INTO...  or a recordset. Whatever you like more. Of course, if you have any further questions, post them.


    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru

    • Marked as answer by DriveEV Thursday, May 24, 2012 12:41 PM
    Thursday, May 24, 2012 9:00 AM
  • Thanks Andrey that's exactly what I was looking for.

    I can expand from that.

    And yes I do agree it's silly to need a Windows Media Player - ActiveX control on the form to get to the library data.

    Thursday, May 24, 2012 1:12 PM