2012-08-09 09:45:04 +00:00
|
|
|
using System;
|
2012-09-29 22:01:15 +00:00
|
|
|
using ANX.Framework.NonXNA.Development;
|
2011-11-17 20:35:25 +00:00
|
|
|
|
2012-08-09 09:45:04 +00:00
|
|
|
// This file is part of the ANX.Framework created by the
|
|
|
|
// "ANX.Framework developer group" and released under the Ms-PL license.
|
|
|
|
// For details see: http://anxframework.codeplex.com/license
|
2011-11-17 20:35:25 +00:00
|
|
|
|
|
|
|
namespace ANX.Framework.Media
|
|
|
|
{
|
2012-09-29 22:01:15 +00:00
|
|
|
[PercentageComplete(100)]
|
|
|
|
[Developer("AstrorEnales")]
|
2012-10-03 20:47:56 +00:00
|
|
|
[TestState(TestStateAttribute.TestState.Untested)]
|
2012-09-29 22:01:15 +00:00
|
|
|
public static class MediaPlayer
|
|
|
|
{
|
|
|
|
#region Events
|
|
|
|
public static event EventHandler<EventArgs> ActiveSongChanged;
|
|
|
|
public static event EventHandler<EventArgs> MediaStateChanged;
|
|
|
|
#endregion
|
|
|
|
|
2012-09-30 13:51:32 +00:00
|
|
|
private static bool isShuffled;
|
2012-09-29 22:01:15 +00:00
|
|
|
private static bool isRepeating;
|
|
|
|
private static float volume;
|
|
|
|
private static MediaState currentState;
|
|
|
|
internal static float VolumeToUse
|
|
|
|
{
|
|
|
|
get { return IsMuted ? 0f : volume; }
|
|
|
|
}
|
|
|
|
|
|
|
|
#region Public
|
2012-09-30 13:51:32 +00:00
|
|
|
public static bool IsShuffled
|
|
|
|
{
|
|
|
|
get { return isShuffled; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
isShuffled = value;
|
|
|
|
Queue.UpdateOrder();
|
|
|
|
}
|
|
|
|
}
|
2012-09-29 22:01:15 +00:00
|
|
|
|
|
|
|
public static bool IsRepeating
|
|
|
|
{
|
|
|
|
get { return isRepeating; }
|
|
|
|
set { isRepeating = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static float Volume
|
|
|
|
{
|
|
|
|
get { return volume; }
|
|
|
|
set { volume = MathHelper.Clamp(value, 0f, 1f); }
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsVisualizationEnabled { get; set; }
|
|
|
|
public static bool IsMuted { get; set; }
|
|
|
|
public static MediaQueue Queue { get; private set; }
|
|
|
|
public static MediaState State
|
|
|
|
{
|
|
|
|
get { return currentState; }
|
|
|
|
private set
|
|
|
|
{
|
|
|
|
if (currentState == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentState = value;
|
2012-10-03 20:47:56 +00:00
|
|
|
if (MediaStateChanged != null)
|
|
|
|
MediaStateChanged(null, EventArgs.Empty);
|
2012-09-29 22:01:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static TimeSpan PlayPosition
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Queue.ActiveSong == null
|
|
|
|
? TimeSpan.Zero : Queue.ActiveSong.NativeSong.PlayPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool GameHasControl
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
static MediaPlayer()
|
|
|
|
{
|
|
|
|
currentState = MediaState.Stopped;
|
|
|
|
volume = 1f;
|
|
|
|
isRepeating = false;
|
|
|
|
IsMuted = false;
|
|
|
|
IsVisualizationEnabled = false;
|
2012-09-30 13:51:32 +00:00
|
|
|
isShuffled = false;
|
2012-09-29 22:01:15 +00:00
|
|
|
Queue = new MediaQueue();
|
|
|
|
FrameworkDispatcher.OnUpdate += Tick;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Play
|
|
|
|
public static void Play(Song song)
|
|
|
|
{
|
|
|
|
Queue.Play(song);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Play(SongCollection songCollection)
|
|
|
|
{
|
|
|
|
Queue.Play(songCollection);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Play(SongCollection songCollection, int index)
|
|
|
|
{
|
|
|
|
Queue.Play(songCollection, index);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Pause
|
|
|
|
public static void Pause()
|
|
|
|
{
|
|
|
|
if (Queue.ActiveSong != null)
|
|
|
|
Queue.ActiveSong.Pause();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Resume
|
|
|
|
public static void Resume()
|
|
|
|
{
|
|
|
|
if (Queue.ActiveSong != null)
|
|
|
|
Queue.ActiveSong.Resume();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Stop
|
|
|
|
public static void Stop()
|
|
|
|
{
|
|
|
|
Queue.Stop();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region MoveNext
|
|
|
|
public static void MoveNext()
|
|
|
|
{
|
|
|
|
Queue.MoveNext(false);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region MovePrevious
|
|
|
|
public static void MovePrevious()
|
|
|
|
{
|
|
|
|
Queue.MovePrevious();
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Tick
|
|
|
|
private static void Tick()
|
|
|
|
{
|
|
|
|
if (Queue.ActiveSong == null)
|
|
|
|
{
|
|
|
|
State = MediaState.Stopped;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-03 20:47:56 +00:00
|
|
|
Queue.ActiveSong.NativeSong.Update();
|
|
|
|
|
2012-09-29 22:01:15 +00:00
|
|
|
State = Queue.ActiveSong.State;
|
|
|
|
if (Queue.ActiveSong.State != MediaState.Stopped)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (Queue.MoveNext(isRepeating))
|
|
|
|
State = MediaState.Playing;
|
|
|
|
|
2012-10-03 20:47:56 +00:00
|
|
|
if (ActiveSongChanged != null)
|
|
|
|
ActiveSongChanged(null, EventArgs.Empty);
|
2012-09-29 22:01:15 +00:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region GetVisualizationData
|
|
|
|
public static void GetVisualizationData(VisualizationData visualizationData)
|
|
|
|
{
|
|
|
|
if (visualizationData == null)
|
|
|
|
throw new ArgumentNullException("visualizationData");
|
|
|
|
|
|
|
|
if (IsVisualizationEnabled == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(Queue.ActiveSong != null)
|
|
|
|
Queue.ActiveSong.NativeSong.GetVisualizationData(visualizationData);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
2011-11-17 20:35:25 +00:00
|
|
|
}
|