Share via


Media Overview

This topic provides a high-level overview about the capabilities—such as playing music and video and accessing pictures—of the Media API in XNA Game Studio. A game can query a media collection for songs, artists, albums, playlist, genres, pictures, and picture albums by using the Microsoft.Xna.Framework.Media namespace. Items in the media library also can be searched based on metadata such as artist name, album name, and musical genre.

Songs as Background Music

Access to the media library, combined with the ability to use playlists, allows games to create interesting background scores that can change with gameplay. Songs can be played directly from the media library, or can be imported by using the Content Pipeline. For more information, see Playing a Song.

Pictures as Textures

Games can obtain and use textures from pictures within a media library. For more information, see Accessing Pictures from a Picture Album.

Video Playback

Games now can add videos to their projects by using the Content Pipeline, and can display those videos on-screen. Videos can be displayed as cut scenes or loading graphics, or as part of an object in 3D space.

To add a video to a project, use the steps outlined in How to: Add Game Assets to a Content Project, and select a Windows Media Video (.wmv) file to import. The video content processor that comes with XNA Game Studio has some limitations:

  1. Video enabled with Digital Rights Management cannot be used.

  2. Video must be encoded to the Windows Media Video 9 "Main" profile by using the VC-1 standard.

  3. Video must be encoded with a constant bit rate (CBR).

  4. Video must include an audio track.

  5. Audio accompanying the video must be Windows Media Audio (.wma) encoded, with a single-pass CBR format.

  6. XNA Game Studio supports the following maximum bit rates:

    Profile Level Maximum bit rate Representative resolutions by frame rate
    Main Low 2 Mbps 320 × 240 @ 24 Hz (QVGA)
      Medium 10 Mbps

    720 × 480 @ 30 Hz (480p)

    720 × 576 @ 25 Hz (576p)

      High 20 Mbps 1280 × 720 @ 30 Hz (720p)

Without an audio track, a video will fail to load, and will display this message: "Video file is invalid. Please make sure that the video is not DRM protected and is a valid single-pass CBR encoded video file."

Once a video is loaded, games can create a new VideoPlayer object to play, pause, and resume the video. Once the video starts, the game can call the GetTexture method to get a Texture2D containing the current frame of video. The texture can be used by SpriteBatch.Draw or rendered by an Effect as part of an object in 3D space.

Silverlight Constraints

Silverlight applications must ensure that FrameworkDispatcher.Update is called regularly in order for "fire and forget" sounds to work correctly. Media Overview throws an InvalidOperationException if FrameworkDispatcher.Update has not been called at least once before making this call. For more information, see Enable XNA Framework Events in Windows Phone Applications.

Concepts

Reference

  • Picture Class
    Provides access to a picture in the media library.
  • Song Class
    Provides access to a song in the song library.
  • Video Class
    Represents a video.
  • VideoPlayer Class
    Provides methods and properties to play back, pause, resume, and stop video. VideoPlayer also exposes repeat, volume, and play position information.