Table of Contents

Class MediaPlayer

Namespace
Microsoft.Xna.Framework.Media
Assembly
MonoGame.Framework.dll

Provides methods and properties to play, pause, resume, and stop songs. MediaPlayer also exposes shuffle, repeat, volume, play position, and visualization capabilities.

public static class MediaPlayer
Inheritance
MediaPlayer
Inherited Members

Properties

GameHasControl

Determines whether the game has control of the background music.

public static bool GameHasControl { get; }

Property Value

bool

Remarks

If a gamer is currently playing their own music as the background to your game, calls to Play(Song), Stop(), Pause(), Resume(), MoveNext(), and MovePrevious() might have no effect, depending on the platform.

IsMuted

Gets or set the muted setting for the media player.

public static bool IsMuted { get; set; }

Property Value

bool

IsRepeating

Gets or sets the repeat setting for the media player.

public static bool IsRepeating { get; set; }

Property Value

bool

Remarks

When set to true, the playback queue will begin playing again after all songs in the queue have been played.

IsShuffled

Gets or sets the shuffle setting for the media player.

public static bool IsShuffled { get; set; }

Property Value

bool

Remarks

When set to true, songs in the playback queue are played in random order rather than from first to last.

IsVisualizationEnabled

Gets or sets the visualization enabled setting for the media player.

public static bool IsVisualizationEnabled { get; }

Property Value

bool

Remarks

Always returns false

PlayPosition

Gets the play position within the currently playing song.

public static TimeSpan PlayPosition { get; }

Property Value

TimeSpan

Queue

Gets the media playback queue, MediaQueue.

public static MediaQueue Queue { get; }

Property Value

MediaQueue

State

Gets the media playback state, MediaState

public static MediaState State { get; }

Property Value

MediaState

Volume

Gets or sets the media player volume

public static float Volume { get; set; }

Property Value

float

Media player volume, from 0.0f (silence) to 1.0f (full volume relative to the current device volume)

Remarks

Volume adjustment is based on a decibel, not multiplicative, scale. Setting Volume to 0.0 subtracts 96 dB from the volume. Setting Volume to 1.0 subtracts 0 dB from the volume. Values in between 0.0f and 1.0f subtract dB from the volume proportionally.

Methods

MoveNext()

Stops currently playing song, moves to the next song in the queue of playing songs and plays it.

public static void MoveNext()

Remarks

If the current song is the last song in the queue, MoveNext() will stay on current song

MovePrevious()

Stops currently playing song, moves to the previous song in the queue of playing songs and plays it.

public static void MovePrevious()

Remarks

If the current song is the first song in the queue, MovePrevious() will stay on current song

Pause()

Pauses the currently playing song.

public static void Pause()

Play(Song)

Play clears the current playback queue, and then queues up the specified song for playback. Playback starts immediately at the beginning of the song.

public static void Play(Song song)

Parameters

song Song

Play(Song, TimeSpan?)

Play clears the current playback queue, and then queues up the specified song for playback. Playback starts immediately at the given position of the song.

public static void Play(Song song, TimeSpan? startPosition)

Parameters

song Song
startPosition TimeSpan?

Play(SongCollection, int)

Play clears the current playback queue, and then queues up the specified song collection for playback. Playback starts immediately at the beginning of the song, specified by song collection index.

public static void Play(SongCollection collection, int index = 0)

Parameters

collection SongCollection
index int

Resume()

Resumes a paused song.

public static void Resume()

Stop()

Stops playing a song.

public static void Stop()

Events

ActiveSongChanged

Raised when the active song changes due to active playback or due to explicit calls to the MoveNext() or MovePrevious() methods.

public static event EventHandler<EventArgs> ActiveSongChanged

Event Type

EventHandler<EventArgs>

MediaStateChanged

Raised when the media player play state changes.

public static event EventHandler<EventArgs> MediaStateChanged

Event Type

EventHandler<EventArgs>