The Media Center Sandbox

Resources and discussion for developing experiences in the Windows Media Center platform.
Welcome to The Media Center Sandbox Sign in | Join | Help
in Search

Accessing Windows Media Center music library

Last post 07-06-2008, 3:43 AM by AndyC. 7 replies.
Sort Posts: Previous Next
  •  06-26-2008, 5:04 AM 7788

    Accessing Windows Media Center music library

    Hi all,

    I have learnt quite a bit and got a fair bit of help through the works of people in this forum without really contributing... out of guilt its time I give back :-)

    I was messing around with trying to get access to the Windows Media Center music library, finding there just wasnt the interface.
    But of course Windows Media Center = Windows Media Player + Pretty.

    So I got into the WMP SDK and found that its quite easy to get access to the Media information in Media Player, and then have it play that stuff with Media Center.

    I really cant be bothered re-typing it all, so here is a link to my blog post on it. This isnt advertising at all, just a pointer :-)
    http://fuzzy-log.blogspot.com/2008/06/windows-media-player-and-center-library.html

    I welcome comments and questions.

    Now time to post a question of my own
  •  06-27-2008, 8:41 AM 7800 in reply to 7788

    Re: Accessing Windows Media Center music library

    For Media Center/WMP integration have a look at this example I presented at the UK 2007 MVP day:

    http://www.digitallivingsolutions.co.uk/downloads/mvpday2007.zip

    It contains slides and source code for creating an add-in that shows your Music library like Media Center.

    Cheers,
    Andrew

  •  07-05-2008, 8:49 AM 7846 in reply to 7800

    Re: Accessing Windows Media Center music library

    Hi!

    Thanks for your code examples. I've got two newbie questions:

    1) Is it possible to use WMPLib in a VMC background app? I get an error when trying to instansiate the WindowsMediaPlayer object.

    2) When I use the same code in a windows forms application I get a bit further. I cannot, however, get any events to fire when using the following code:

    private void Form1_Load(object sender, EventArgs e)
    {
     player.CurrentItemChange += new _WMPOCXEvents_CurrentItemChangeEventHandler(player_CurrentItemChange);
    }

    private void player_CurrentItemChange(object sender)
    {
        MessageBox.Show(player.currentMedia.name);
    }

    I'm guessing the problem is that I'm creating a local WindowsMediaPlayer object (so I'm not referencing the same WindowsMediaPlayer object that VMC is using?

    Please help!

     

  •  07-05-2008, 11:23 AM 7847 in reply to 7846

    Re: Accessing Windows Media Center music library

    There shouldn't be any problem in instantiating WMPLib in a background add-in - I have apps that do that.  

    You're right on the events with WMP - to reference the same WMP instance as Media Center, you need to create a remoted WMP instance, which is very difficult to do in managed code (and documented on MSDN as not supported).   If you don't really need this functionality I'd avoid it, but if you do, start looking at "remoting windows media player" on MSDN and start learning C++ to make a wrapper object!

    Cheers,
    Andrew

  •  07-05-2008, 1:51 PM 7848 in reply to 7847

    Re: Accessing Windows Media Center music library

    Puh!

    All I want to do is to intercept when a video/DVD is started in VMC and get the name of it. I now have two (difficult) ways of doing this (1) remoting as suggested by Andy above or (2) MSAS. If there is no more option, is MSAS the preferred way to go?

  •  07-05-2008, 11:44 PM 7851 in reply to 7848

    Re: Accessing Windows Media Center music library

    Lucky you mentioned that, as it saves you a lot of headaches trying to get a remoted WMP working - Media Center doesn't use WMP for DVDs or Videos, so you would have got nothing back.  WMP is only used for playing music and holding the library.

    Have a look at the PropertyChanged events on MediaCenterEnvironment, MediaExperience, and MediaTransport to see if any of these can help you, and then look at MediaMetadata for the DVD name.  This avoids MSAS as well if you can find an event that looks like something you need.

    Cheers,
    Andrew

  •  07-06-2008, 12:30 AM 7852 in reply to 7851

    Re: Accessing Windows Media Center music library

    Thanks Andy!

    I've tried the MediaCenterEnvironment and MediaExperience events (with no luck). How do I, in a background app, get a handle to the MediaTransport (since it's not a part of the AddInHost object)?

  •  07-06-2008, 3:43 AM 7853 in reply to 7852

    Re: Accessing Windows Media Center music library

    It's called "Transport" and is off MediaExperience I think (going from memory).   You need to know that MediaTransport is a wrapper for a MarshalByRefObject which you can't set a lifetime on, so you will need to keep polling something on the transport every few minutes to keep it alive.

    Also, the MediaTransport changes each time the media is changed - so, change from music to DVD and the MediaTransport object will change (the old one will no longer receive events).  This is why you'll need to catch a PropertyChanged for "Transport" somewhere along the line.   This may not be possible in a background add-in, as your add-in's Launch method runs on the application thread, and doesn't allow the Media Center dispatcher to fire events properly, and you can't complete the Launch method as your add-in will close if do.

    So having said all that, it may be back to MSAS afterall!

    Cheers,
    Andrew

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems