Accessing the Windows Media Center Object Model in Markup

To access the Windows Media Center managed code object model API in MCML, you must reference the namespaces using xmlns statements. All Windows Media Center services start with the AddInHost class, which is located in the Microsoft.MediaCenter.Hosting namespace. The following example shows how to reference this in MCML:

xmlns:addin="assembly://Microsoft.MediaCenter/Microsoft.MediaCenter.Hosting"

Then, create the objects in the Locals section of the UI.

<Locals>
    <addin:AddInHost Name="AddInHost" />
</Locals>

Whenever you attempt to access the managed code object model, it is recommended that you check whether Windows Media Center is the foreground application using the ApplicationContext.IsForegroundApplication property. You can create rules that evaluate the Windows Media Center environment and conditions to determine whether to proceed with other actions, such as playing media. In the following example, a rule is used to determine whether Windows Media Center is the foreground application before a video as the background.

      <Rule>
        <Conditions>
          <Equality Source="[AddInHost.ApplicationContext.IsForegroundApplication]" Value="true" />
          <Equality Source="[AddInHost.MediaCenterEnvironment.MediaExperience.MediaType.ToString]" Value="Video" />
        </Conditions>
        <Actions>
          <Set Target="[AddInHost.MediaCenterEnvironment.BackgroundMode]"
               Value="Video" />
        </Actions>
      </Rule>

For more information about using rules, see Setting Up Rules.

Sample Explorer

  • Fundamentals > Object Model Access
  • MediaCenterEnvironment > Media Collection Mixed

See Also