Working with Audio and Video

Audio

You can play sound effects in MCML by using a PlaySound action in a custom rule. In the following example, a sound is played in response to a click event.

<Rules>
    <!-- Watch for the click event. -->
    <Changed Source="[Charge.Invoked]">

        <Actions>
            <!-- Play a sound. -->
            <PlaySound Sound="file://Launch.wav"/>
        </Actions>
    </Changed>
</Rules>

Video

To display video in MCML, use the Video view item. The Video element does not provide a way to start, stop, or change the content that is playing, so to control video you must use the Windows Media Center API.

The current video that is playing is displayed within a Video view item, although the size of the view item does not affect the size of the video. When configuring the layout, set a minimum size or use anchor points for Form or Anchor layout.

You can capture a video click event (the user clicks or selects a view port) by placing a Video view item within a UI that has implemented a ClickHandler, with HandlerStage set to "Routed" (if you want to intercept it before the video is displayed full screen).

You can create effects simply by displaying multiple view items within a UI. The first item has the highest z-order; that is, the first item is displayed on top of the next item, and so forth.

The following example shows a simple UI to display a video file in full screen.

<Mcml xmlns="http://schemas.microsoft.com/2008/mcml"
      xmlns:cor="assembly://MSCorlib/System"
      xmlns:addin="assembly://Microsoft.MediaCenter/Microsoft.MediaCenter.Hosting" >

  <UI Name="VideoPlayback">

    <Properties>
      <cor:String Name="VideoPath" String="C:\Resources\Video01.wmv"/>
    </Properties>

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

    <Rules>
      <Rule>
        <Actions>
          <Invoke Target="[AddInHost.MediaCenterEnvironment.PlayMedia]"
                  mediaType="Video" media="[VideoPath]" addToQueue="false"/>
          <Invoke Target="[AddInHost.MediaCenterEnvironment.MediaExperience.GoToFullScreen]"/>
        </Actions>
      </Rule>
    </Rules>

    <Content>
          <Video MinimumSize="400,300" />
    </Content>
  </UI>

</Mcml>

Sample Explorer

  • View Items – Video > Video
  • MediaCenterEnvironment > PlayMedia - Audio
  • MediaCenterEnvironment > PlayMedia - Video
  • MediaExperience > all samples

See Also

Show: