MediaLibrary Class
XNA Game Studio 3.1
MediaLibrary Class
Provides access to songs, playlists, and pictures in the device's media library.

Namespace: Microsoft.Xna.Framework.Media
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

Syntax

public sealed class MediaLibrary
Remarks

MediaLibrary provides the following properties that return media collections: Albums, Artists, Genres, Pictures, Playlists, and Songs. Each property returns a collection object that can be enumerated and indexed. The collection object represents all media of that type in the device's media library.

The media collections do not retrieve or instantiate all media objects immediately. Instead, when needed, you can use the collections later to retrieve individual media objects, such as Song and Artist objects.

On Windows, MediaLibrary cannot find any songs unless the Windows Media Player previously found songs on the system. That means that Windows Media Player must first search the system for music before any songs can be accessed through MediaLibrary.

Example

The following sample fragment demonstrates how to use MediaLibrary to retrieve and play a song.

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace ZuneSimpleSongPlay
{
    static class Program
    {
        static void Main(string[] args)
        {
            MediaLibrary library = new MediaLibrary();
            SongCollection songs = library.Songs;
            Song song = songs[0];
            MediaPlayer.Play(song);

            while (!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back))
            {
                ;
            }
        }
    }
}
Dd254846.note(en-us,XNAGameStudio.31).gifNote
You may get an exception when you try to play DRM protected music.
See Also

Tasks

Reference

Platforms

Xbox 360, Windows XP SP2, Windows Vista, Zune
© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View