SIGN UP MEMBER LOGIN:    
ARTICLE

How to use Album in XNA

Posted by Ibrahim Ersoy Articles | XNA with C# August 09, 2010
In this article I will show you how to use Album in XNA.
Reader Level:

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:

1.gif
 
Getting Album's Artist:

2.gif
 
Getting Album's Duration:

3.gif
 
Getting Album's Genre:

4.gif
 
GetAlbumArt function returns Stream of the album image data:

5.gif
 
GetThumbnail returns small image data:

6.gif
 
HasArt returns if the album has an album art:

7.gif
 
Getting Album's Name:

8.gif
 
Getting Album's Songs:

9.gif 

Hope this article helped you understand Album,Song and MediaLibrary Structures.

Login to add your contents and source code to this article
share this article :
post comment
 

Why album come from C:\Users\Public\Music\Sample Music Have the format of the songs had requrment?

Posted by junben liu Jun 11, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor