I haven't really covered how to interact with Media Center itself through much of these posts.
Although there isn't a lot you can actually get Media Center to do, it's often vital to make your application play different types of media or have some control over the Media Center experience - such as creating notifications, playing sounds etc.
All of this is done through the AddInHost object - http://msdn.microsoft.com/en-us/library/aa468251.aspx.
One of the nice touches is that the AddInHost class has a static member called current that contains the interface to Media Center - you don't need to go to any great lengths to access it. Within the AddInHost object are a number of properties that give you feedback or control on the state of Media Center. They are all relatively well documented in the SDK, so I'll only cover the most important.
MediaCenterEnvironment (http://msdn.microsoft.com/en-us/library/bb189320.aspx) is used to perform real control over Media Center. You can use this class to launch new addins, to navigate to new pages, play media and show dialog boxes equivalent to the normal Windows 'MessageBox'. It can also be used to get and set properties, such as volume levels, mode of the screen, parental controls level etc.
To navigate to a new MCML page, you use the following line...
AddInHost.Current.MediaCenterEnvironment.NavigateToPage(<page>)
To show a message - which is very good for debugging - you can use...
AddInHost.Current.MediaCenterEnvironment.Dialog(<text>,<title>,<buttons>,<timeout>,<ismodal>)
This function is very similar to the Win32 'MsgBox' or the .NET MessageBox class. The only really new thing is the 'IsModal' property, which is used to tell Media Center if the program should halt and wait for a response (true) or if it should allow the program to continue in the background (false).
And one of the most important....
AddInHost.Current.MediaCenterEnvironment.PlayMedia(<mediatype>,<media>,<addtoqueue>)
This function is used to play a media item. The actual 'Media' parameter takes the URL/path to your media. You should use 'addtoqueue' only if you are adding music - using this parameter with other types of item can cause issues.
This is one of the very few functions you can use that will actually crash Media Center, so be careful. All other functions are completely isolated from Media Center, so if you crash you only take out your addin rather than Media Center as a whole. With PlayMedia, you can bring down the entire Media Center experience by playing invalid files. Please take care with all URLs you pass to this function.
For videos or pictures, after a call to PlayMedia you may want to consider calling AddInHost.Current.MediaCenterEnvironment.MediaExperience.GoToFullScreen - which (fairly obviously) will show your media in fullscreen, rather than appearing in the bottom corner of your program.
A word of warning for people debugging in MCMLPad - because your addin isn't launched from Media Center with MCMLPad, you will still have access to the AddInHost object, but the current member will be empty. If you are planning on debugging with MCMLPad, please ensure you place a check that AddInHost.Current is not null before each call that uses the object.
Posted
Nov 07 2008, 07:39 AM
by
IgnoranceIsBliss