In this article I will show you how to use Album in XNA.
So lets start with what is an album and what does it do?
The Album class provides information about an album, including the album's Name, Artist, and Songs.
You can obtain an Album object through the AlbumCollection.Item indexer and the Song.Album property.
Album provides access to an album in the media library.
So you will have to work closely with MediaLibrary object.
For example you can load anything from a MediaLibrary;
MediaLibrary library = new MediaLibrary();
AlbumCollection
albums = library.Albums;
Album alb1 =
albums[0];
It may be an Album,Song or a Picture.Anthing you can call within MediaLibrary.To display them: you need to use MediaLibrary.
A Medialibrary that plays the specified song from a SongCollection:
MediaLibrary library = new MediaLibrary();
SongCollection songs
= library.Songs;
Song song =
songs[0];
MediaPlayer.Play(song);
We will create a small application that plays sample songs from an album using MediaPlayer.
//Variables
MediaLibrary sampleMediaLibrary;
Random rand;
//Game1
TargetElapsedTime = TimeSpan.FromSeconds(1
/ 30.0);
sampleMediaLibrary = new MediaLibrary();
rand = new Random();
//Initialize
MediaPlayer.Stop();
int i =
rand.Next(0, sampleMediaLibrary.Albums.Count - 1);
MediaPlayer.Play(sampleMediaLibrary.Albums[i].Songs[0]);
Run your application and after a couple of seconds you will hear songs.
The Album is getting songs from:
C:\Users\Public\Music\Sample Music
Now lets have a look at Album's Structure:
Creating a new instance of an Album:
Getting Album's Artist:
Getting Album's Duration:
Getting Album's Genre:
GetAlbumArt function returns Stream of the album image data:
GetThumbnail returns small image data:
HasArt returns if the album has an album art:
Getting Album's Name:
Getting Album's Songs:
Hope this article helped you understand Album,Song and MediaLibrary Structures.