Playing a Song from a URI

Demonstrates how to use the MediaPlayer to play a song from a Uniform Resource Identifier (URI).

Playing a Song from a URI

To play a song from a URI

The following steps show you how to play an .mp3 song located on the Internet.

  1. Set MediaPlayer play state to stopped.

  2. Declare a new instance of Uri using the full URI path to the song.

    Uri uriStreaming = new Uri("");
  3. Use the FromUri method to supply an arbitrary string name for the URI, and then pass the Uri object you created in the previous step.

    Song song = Song.FromUri("StreamingUri", uriStreaming);
  4. Play the song.



  • Playing a Song
    Demonstrates how to play a song from a user's media library.
  • Media Overview
    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.


  • MediaPlayer Class
    Provides methods and properties to play, pause, resume, and stop songs. MediaPlayer also exposes shuffle, repeat, volume, play position, and visualization capabilities.
  • Song Class
    Provides access to a song in the song library.