Finished Task #539 and implemented some VideoPlayer logic

This commit is contained in:
SND\AstrorEnales_cp 2012-09-30 07:43:41 +00:00 committed by Konstantin Koch
parent 2e581c6d53
commit 3bf2261cd0
21 changed files with 346 additions and 466 deletions

View File

@ -11,7 +11,7 @@ namespace ANX.Framework.Input
[TestState(TestStateAttribute.TestState.Tested)]
public static class GamePad
{
private static IGamePad gamePad;
private static readonly IGamePad gamePad;
static GamePad()
{

View File

@ -70,7 +70,7 @@ namespace ANX.Framework.Input
public override bool Equals(object obj)
{
if (obj != null && obj.GetType() == typeof(GamePadDPad))
if (obj is GamePadDPad)
return this == (GamePadDPad)obj;
return false;

View File

@ -86,7 +86,7 @@ namespace ANX.Framework.Input
public override bool Equals(object obj)
{
if (obj != null && obj.GetType() == typeof(GamePadState))
if (obj is GamePadState)
return this == (GamePadState)obj;
return false;

View File

@ -12,22 +12,15 @@ namespace ANX.Framework.Input
[TestState(TestStateAttribute.TestState.Tested)]
public static class Keyboard
{
private static IKeyboard keyboard;
private static readonly IKeyboard keyboard;
internal static IntPtr WindowHandle
{
get
{
return keyboard != null ? keyboard.WindowHandle : IntPtr.Zero;
}
set
{
if (keyboard != null)
keyboard.WindowHandle = value;
}
}
internal static IntPtr WindowHandle
{
get { return keyboard.WindowHandle; }
set { keyboard.WindowHandle = value; }
}
static Keyboard()
static Keyboard()
{
keyboard = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard;
}

View File

@ -15,39 +15,22 @@ namespace ANX.Framework.Input.MotionSensing
{
public class MotionSensingDevice
{
private static IMotionSensingDevice motionSensingDevice;
static MotionSensingDevice()
{
motionSensingDevice = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().MotionSensingDevice;
}
private static readonly IMotionSensingDevice motionSensingDevice;
public static GraphicsDevice GraphicsDevice
{
get
{
if (motionSensingDevice != null)
{
return motionSensingDevice.GraphicsDevice;
}
return null;
}
set
{
if (motionSensingDevice != null)
{
motionSensingDevice.GraphicsDevice = value;
}
}
get { return motionSensingDevice.GraphicsDevice; }
set { motionSensingDevice.GraphicsDevice = value; }
}
public static MotionSensingDeviceType DeviceType
{
get
{
return motionSensingDevice.DeviceType;
}
get { return motionSensingDevice.DeviceType; }
}
static MotionSensingDevice()
{
motionSensingDevice = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().MotionSensingDevice;
}
public static MotionSensingDeviceState GetState()

View File

@ -12,35 +12,27 @@ namespace ANX.Framework.Input
[TestState(TestStateAttribute.TestState.Tested)]
public static class Mouse
{
private static IMouse mouse;
private static readonly IMouse mouse;
public static IntPtr WindowHandle
{
get
{
return mouse != null ? mouse.WindowHandle : IntPtr.Zero;
}
set
{
if (mouse != null)
mouse.WindowHandle = value;
}
}
public static IntPtr WindowHandle
{
get { return mouse.WindowHandle; }
set { mouse.WindowHandle = value; }
}
static Mouse()
static Mouse()
{
mouse = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse;
}
public static MouseState GetState()
{
return (mouse != null) ? mouse.GetState() : new MouseState();
return mouse.GetState();
}
public static void SetPosition(int x, int y)
{
if (mouse != null)
mouse.SetPosition(x, y);
mouse.SetPosition(x, y);
}
}
}

View File

@ -1,7 +1,6 @@
using System;
using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.Development;
using ANX.Framework.NonXNA.InputSystem;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
@ -13,106 +12,63 @@ namespace ANX.Framework.Input.Touch
[TestState(TestStateAttribute.TestState.Untested)]
public static class TouchPanel
{
#region Private
private static ITouchPanel nativeTouchPanel;
#endregion
private static readonly ITouchPanel nativeTouchPanel;
#region Public
public static GestureType EnabledGestures
{
get
{
return nativeTouchPanel.EnabledGestures;
}
set
{
nativeTouchPanel.EnabledGestures = value;
}
}
public static GestureType EnabledGestures
{
get { return nativeTouchPanel.EnabledGestures; }
set { nativeTouchPanel.EnabledGestures = value; }
}
public static bool IsGestureAvailable
{
get
{
return nativeTouchPanel.IsGestureAvailable;
}
}
public static bool IsGestureAvailable
{
get { return nativeTouchPanel.IsGestureAvailable; }
}
public static IntPtr WindowHandle
{
get
{
return nativeTouchPanel.WindowHandle;
}
set
{
nativeTouchPanel.WindowHandle = value;
}
}
public static IntPtr WindowHandle
{
get { return nativeTouchPanel.WindowHandle; }
set { nativeTouchPanel.WindowHandle = value; }
}
public static DisplayOrientation DisplayOrientation
{
get
{
return nativeTouchPanel.DisplayOrientation;
}
set
{
nativeTouchPanel.DisplayOrientation = value;
}
}
public static DisplayOrientation DisplayOrientation
{
get { return nativeTouchPanel.DisplayOrientation; }
set { nativeTouchPanel.DisplayOrientation = value; }
}
public static int DisplayWidth
{
get
{
return nativeTouchPanel.DisplayWidth;
}
set
{
nativeTouchPanel.DisplayWidth = value;
}
}
public static int DisplayWidth
{
get { return nativeTouchPanel.DisplayWidth; }
set { nativeTouchPanel.DisplayWidth = value; }
}
public static int DisplayHeight
{
get
{
return nativeTouchPanel.DisplayHeight;
}
set
{
nativeTouchPanel.DisplayHeight = value;
}
}
#endregion
public static int DisplayHeight
{
get { return nativeTouchPanel.DisplayHeight; }
set { nativeTouchPanel.DisplayHeight = value; }
}
#endregion
#region Constructor
static TouchPanel()
{
nativeTouchPanel = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().TouchPanel;
}
#endregion
#region GetCapabilities
public static TouchPanelCapabilities GetCapabilities()
{
return nativeTouchPanel.GetCapabilities();
}
#endregion
#region ReadGesture
public static GestureSample ReadGesture()
{
return nativeTouchPanel.ReadGesture();
}
#endregion
#region GetState
public static TouchCollection GetState()
{
return nativeTouchPanel.GetState();
}
#endregion
}
}

View File

@ -6,11 +6,11 @@ using ANX.Framework.NonXNA.Development;
namespace ANX.Framework.Input.Touch
{
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public struct TouchPanelCapabilities
{
public bool IsConnected { get; set; }
public int MaximumTouchCount { get; set; }
}
[PercentageComplete(100)]
[TestState(TestStateAttribute.TestState.Tested)]
public struct TouchPanelCapabilities
{
public bool IsConnected { get; set; }
public int MaximumTouchCount { get; set; }
}
}

View File

@ -10,31 +10,21 @@ namespace ANX.Framework.Media
{
public sealed class ArtistCollection : IEnumerable<Artist>, IEnumerable, IDisposable
{
private List<Artist> artists;
private readonly List<Artist> artists;
public bool IsDisposed
{
get;
private set;
}
public bool IsDisposed { get; private set; }
public int Count
{
get
{
return artists.Count;
}
}
public int Count
{
get { return artists.Count; }
}
public Artist this[int index]
{
get
{
return artists[index];
}
}
public Artist this[int index]
{
get { return artists[index]; }
}
internal ArtistCollection()
internal ArtistCollection()
{
artists = new List<Artist>();
IsDisposed = false;

View File

@ -10,31 +10,21 @@ namespace ANX.Framework.Media
{
public sealed class GenreCollection : IEnumerable<Genre>, IEnumerable, IDisposable
{
private List<Genre> genres;
private readonly List<Genre> genres;
public bool IsDisposed
{
get;
private set;
}
public bool IsDisposed { get; private set; }
public int Count
{
get
{
return genres.Count;
}
}
public int Count
{
get { return genres.Count; }
}
public Genre this[int index]
{
get
{
return genres[index];
}
}
public Genre this[int index]
{
get { return genres[index]; }
}
internal GenreCollection()
internal GenreCollection()
{
genres = new List<Genre>();
IsDisposed = false;

View File

@ -1,6 +1,5 @@
using System;
using System.IO;
using ANX.Framework.NonXNA;
using ANX.Framework.NonXNA.PlatformSystem;
// This file is part of the ANX.Framework created by the
@ -13,94 +12,61 @@ namespace ANX.Framework.Media
{
private INativeMediaLibrary nativeLibrary;
#region Public
public MediaSource MediaSource
{
get;
private set;
}
#region Public
public bool IsDisposed { get; private set; }
public MediaSource MediaSource { get; private set; }
public PictureCollection Pictures
{
get
{
return nativeLibrary.GetPictures();
}
}
public PictureAlbum RootPictureAlbum
{
get
{
return nativeLibrary.GetRootPictureAlbum();
}
}
public PictureCollection SavedPictures
{
get
{
return nativeLibrary.GetSavedPictures();
}
}
public SongCollection Songs
{
get
{
return nativeLibrary.GetSongs();
}
}
public ArtistCollection Artists
{
get
{
return nativeLibrary.GetArtists();
}
}
public AlbumCollection Albums
{
get
{
return nativeLibrary.GetAlbums();
}
}
public PlaylistCollection Playlists
{
get
{
return nativeLibrary.GetPlaylists();
}
}
public GenreCollection Genres
{
get
{
return nativeLibrary.GetGenres();
}
}
public PictureCollection Pictures
{
get { return nativeLibrary.GetPictures(); }
}
public bool IsDisposed
{
get;
private set;
}
#endregion
public PictureAlbum RootPictureAlbum
{
get { return nativeLibrary.GetRootPictureAlbum(); }
}
public PictureCollection SavedPictures
{
get { return nativeLibrary.GetSavedPictures(); }
}
public SongCollection Songs
{
get { return nativeLibrary.GetSongs(); }
}
public ArtistCollection Artists
{
get { return nativeLibrary.GetArtists(); }
}
public AlbumCollection Albums
{
get { return nativeLibrary.GetAlbums(); }
}
public PlaylistCollection Playlists
{
get { return nativeLibrary.GetPlaylists(); }
}
public GenreCollection Genres
{
get { return nativeLibrary.GetGenres(); }
}
#endregion
#region Constructor
public MediaLibrary()
{
nativeLibrary = PlatformSystem.Instance.CreateMediaPlayer();
nativeLibrary = PlatformSystem.Instance.CreateMediaLibrary();
MediaSource = MediaSource.GetAvailableMediaSources()[0];
}
public MediaLibrary(MediaSource setSource)
{
nativeLibrary = PlatformSystem.Instance.CreateMediaPlayer();
nativeLibrary = PlatformSystem.Instance.CreateMediaLibrary();
MediaSource = setSource;
}
@ -113,13 +79,12 @@ namespace ANX.Framework.Media
#region Dispose
public void Dispose()
{
if (IsDisposed == false)
{
IsDisposed = true;
if (IsDisposed)
return;
nativeLibrary.Dispose();
nativeLibrary = null;
}
IsDisposed = true;
nativeLibrary.Dispose();
nativeLibrary = null;
}
#endregion

View File

@ -8,37 +8,19 @@ namespace ANX.Framework.Media
{
public sealed class Video
{
#region Public
public TimeSpan Duration
{
get;
private set;
}
public int Width
{
get;
private set;
}
public int Height
{
get;
private set;
}
public float FramesPerSecond
{
get;
private set;
}
public VideoSoundtrackType VideoSoundtrackType
{
get;
private set;
}
#endregion
internal TimeSpan PlayPosition
{
get { throw new NotImplementedException(); }
//get { return nativeVideo.PlayPosition; }
}
#region Public
public TimeSpan Duration { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
public float FramesPerSecond { get; private set; }
public VideoSoundtrackType VideoSoundtrackType { get; private set; }
#endregion
#region Constructor
internal Video(int duration, int width, int height, float framesPerSecond, VideoSoundtrackType soundtrackType)
@ -50,5 +32,29 @@ namespace ANX.Framework.Media
VideoSoundtrackType = soundtrackType;
}
#endregion
internal void Play()
{
// TODO: nativeVideo.Play();
throw new NotImplementedException();
}
internal void Pause()
{
// TODO: nativeVideo.Pause();
throw new NotImplementedException();
}
internal void Resume()
{
// TODO: nativeVideo.Resume();
throw new NotImplementedException();
}
internal void Stop()
{
// TODO: nativeVideo.Stop();
throw new NotImplementedException();
}
}
}

View File

@ -9,34 +9,31 @@ namespace ANX.Framework.Media
{
public sealed class VideoPlayer : IDisposable
{
public bool IsDisposed
{
get;
private set;
}
private float volume;
internal float VolumeToUse
{
get { return IsMuted ? 0f : volume; }
}
public TimeSpan PlayPosition
public Video Video { get; private set; }
public bool IsMuted { get; set; }
public bool IsDisposed { get; private set; }
public TimeSpan PlayPosition
{
get
{
throw new NotImplementedException();
}
get { return Video == null ? TimeSpan.Zero : Video.PlayPosition; }
}
public float Volume
{
get
{
throw new NotImplementedException();
}
}
get { return volume; }
set
{
if (value < 0f || value > 1f)
throw new ArgumentOutOfRangeException("value");
public bool IsMuted
{
get
{
throw new NotImplementedException();
}
volume = value;
}
}
public bool IsLooped
@ -46,15 +43,7 @@ namespace ANX.Framework.Media
throw new NotImplementedException();
}
}
public Video Video
{
get
{
throw new NotImplementedException();
}
}
public MediaState State
{
get
@ -65,6 +54,8 @@ namespace ANX.Framework.Media
public VideoPlayer()
{
IsMuted = false;
volume = 1f;
IsDisposed = false;
}
@ -75,31 +66,38 @@ namespace ANX.Framework.Media
public void Dispose()
{
if (IsDisposed == false)
{
IsDisposed = true;
throw new NotImplementedException();
}
if (IsDisposed)
return;
IsDisposed = true;
Video = null;
}
public void Play(Video video)
{
throw new NotImplementedException();
{
if (video == null)
throw new ArgumentNullException("video");
Video = video;
video.Play();
}
public void Pause()
{
throw new NotImplementedException();
{
if (Video != null)
Video.Pause();
}
public void Resume()
{
throw new NotImplementedException();
{
if (Video != null)
Video.Resume();
}
public void Stop()
{
throw new NotImplementedException();
{
if (Video != null)
Video.Stop();
}
public Texture2D GetTexture()

View File

@ -82,9 +82,10 @@ namespace ANX.Framework.NonXNA
public ITouchPanel GetDefaultTouchPanel()
{
ValidateWindowHandle();
var touchPanel = GetDefaultCreator<ITouchPanelCreator>().CreateDevice();
touchPanel.WindowHandle = WindowHandle;
#if !WINDOWSMETRO
touchPanel.WindowHandle = WindowHandle;
#endif
return touchPanel;
}
#endregion
@ -99,11 +100,8 @@ namespace ANX.Framework.NonXNA
#region CreateDefaultMouse
public IMouse CreateDefaultMouse()
{
#if !WINDOWSMETRO
ValidateWindowHandle();
#endif
var mouse = GetDefaultCreator<IMouseCreator>().CreateDevice();
#if !WINDOWSMETRO
mouse.WindowHandle = WindowHandle;
#endif
@ -139,7 +137,7 @@ namespace ANX.Framework.NonXNA
{
var creators = deviceCreators[creatorType];
if (creators.Count > 0)
return (T)creators.Values.First<IInputDeviceCreator>();
return (T)creators.Values.First();
}
throw new Exception("Unable to find a default creator for type " + creatorType);
@ -149,8 +147,10 @@ namespace ANX.Framework.NonXNA
#region ValidateWindowHandle
private void ValidateWindowHandle()
{
#if !WINDOWSMETRO
if (WindowHandle == IntPtr.Zero)
throw new Exception("Unable to create a mouse instance because the WindowHandle was not set.");
throw new Exception("Unable to create a mouse instance because the WindowHandle was not set.");
#endif
}
#endregion
}

View File

@ -20,7 +20,7 @@ namespace ANX.Framework.NonXNA.PlatformSystem
Stream OpenReadFilestream(string filepath);
INativeMediaLibrary CreateMediaPlayer();
INativeMediaLibrary CreateMediaLibrary();
IList<MediaSource> GetAvailableMediaSources();
}
}

View File

@ -165,14 +165,14 @@ namespace ANX.Framework.NonXNA.PlatformSystem
return runtimeInstance.OpenReadFilestream(filepath);
}
public INativeMediaLibrary CreateMediaPlayer()
public INativeMediaLibrary CreateMediaLibrary()
{
if (runtimeInstance == null)
{
throw new PlatformSystemInstanceException();
}
return runtimeInstance.CreateMediaPlayer();
return runtimeInstance.CreateMediaLibrary();
}
public IList<MediaSource> GetAvailableMediaSources()

View File

@ -6,118 +6,125 @@ using ANX.Framework.NonXNA;
namespace ANX.InputSystem.Standard
{
public class Creator : IInputSystemCreator
{
private IKeyboard keyboard;
private IMouse mouse;
private IGamePad gamePad;
private ITouchPanel touchPanel;
public string Name
{
get
{
return "Standard";
}
}
public int Priority
{
get
{
return 0;
}
}
public bool IsSupported
{
get
{
return true;
}
}
public ITouchPanel TouchPanel
{
get
{
if (touchPanel == null)
{
Logger.Info("Creating a new TouchPanel device.");
PreventSystemChange();
touchPanel = InputDeviceFactory.Instance.GetDefaultTouchPanel();
}
return touchPanel;
}
}
public IGamePad GamePad
{
get
{
if (gamePad == null)
{
Logger.Info("Creating a new GamePad device.");
PreventSystemChange();
gamePad = InputDeviceFactory.Instance.CreateDefaultGamePad();
}
return gamePad;
}
}
public IMouse Mouse
{
get
{
if (mouse == null)
{
mouse = InputDeviceFactory.Instance.CreateDefaultMouse();
if (mouse == null)
throw new NoInputDeviceException("Couldn't find a default mouse device creator. Unable to create a mouse instance.");
Logger.Info("created a new Mouse device");
PreventSystemChange();
}
return this.mouse;
}
}
public IKeyboard Keyboard
{
get
{
if (keyboard == null)
{
keyboard = InputDeviceFactory.Instance.CreateDefaultKeyboard();
if (keyboard == null)
throw new NoInputDeviceException("Couldn't find a default keyboard device creator. Unable to create a keyboard instance.");
Logger.Info("created a new Keyboard device");
PreventSystemChange();
}
return this.keyboard;
}
}
public class Creator : IInputSystemCreator
{
private const string CreationLogMessage = "Creating a new {0} device.";
private const string CreationThrowMessage =
"Couldn't find a default {0} device creator. Unable to create a {0} instance.";
#if XNAEXT
public IMotionSensingDevice MotionSensingDevice
{
get
{
Logger.Info("Creating a new MotionSensingDevice device.");
PreventSystemChange();
return InputDeviceFactory.Instance.CreateDefaultMotionSensingDevice();
}
}
private IMotionSensingDevice motionSensingDevice;
#endif
private IKeyboard keyboard;
private IMouse mouse;
private IGamePad gamePad;
private ITouchPanel touchPanel;
public string Name
{
get { return "Standard"; }
}
public int Priority
{
get { return 0; }
}
public bool IsSupported
{
get { return true; }
}
public ITouchPanel TouchPanel
{
get
{
if (touchPanel == null)
{
Logger.Info(string.Format(CreationLogMessage, "TouchPanel"));
PreventSystemChange();
touchPanel = InputDeviceFactory.Instance.GetDefaultTouchPanel();
if (touchPanel == null)
throw new NoInputDeviceException(string.Format(CreationThrowMessage, "touchPanel"));
}
return touchPanel;
}
}
public IGamePad GamePad
{
get
{
if (gamePad == null)
{
Logger.Info(string.Format(CreationLogMessage, "GamePad"));
PreventSystemChange();
gamePad = InputDeviceFactory.Instance.CreateDefaultGamePad();
if (gamePad == null)
throw new NoInputDeviceException(string.Format(CreationThrowMessage, "gamePad"));
}
return gamePad;
}
}
public IMouse Mouse
{
get
{
if (mouse == null)
{
Logger.Info(string.Format(CreationLogMessage, "Mouse"));
PreventSystemChange();
mouse = InputDeviceFactory.Instance.CreateDefaultMouse();
if (mouse == null)
throw new NoInputDeviceException(string.Format(CreationThrowMessage, "mouse"));
}
return mouse;
}
}
public IKeyboard Keyboard
{
get
{
if (keyboard == null)
{
Logger.Info(string.Format(CreationLogMessage, "Keyboard"));
PreventSystemChange();
keyboard = InputDeviceFactory.Instance.CreateDefaultKeyboard();
if (keyboard == null)
throw new NoInputDeviceException(string.Format(CreationThrowMessage, "keyboard"));
}
return keyboard;
}
}
#if XNAEXT
public IMotionSensingDevice MotionSensingDevice
{
get
{
if (motionSensingDevice == null)
{
Logger.Info(string.Format(CreationLogMessage, "MotionSensing"));
PreventSystemChange();
motionSensingDevice = InputDeviceFactory.Instance.CreateDefaultMotionSensingDevice();
if (motionSensingDevice == null)
throw new NoInputDeviceException(string.Format(CreationThrowMessage, "motionSensing"));
}
return motionSensingDevice;
}
}
#endif
private void PreventSystemChange()
{
AddInSystemFactory.Instance.PreventSystemChange(AddInType.InputSystem);
}
}
private static void PreventSystemChange()
{
AddInSystemFactory.Instance.PreventSystemChange(AddInType.InputSystem);
}
}
}

View File

@ -64,7 +64,7 @@ namespace ANX.PlatformSystem.Linux
#endregion
#region CreateMediaPlayer (TODO)
public INativeMediaLibrary CreateMediaPlayer()
public INativeMediaLibrary CreateMediaLibrary()
{
throw new NotImplementedException();
}

View File

@ -71,7 +71,7 @@ namespace ANX.PlatformSystem.Metro
throw new NotImplementedException();
}
public INativeMediaLibrary CreateMediaPlayer()
public INativeMediaLibrary CreateMediaLibrary()
{
throw new NotImplementedException();
}

View File

@ -67,7 +67,7 @@ namespace ANX.PlatformSystem.PsVita
#endregion
#region CreateMediaPlayer (TODO)
public INativeMediaLibrary CreateMediaPlayer()
public INativeMediaLibrary CreateMediaLibrary()
{
throw new NotImplementedException();
}

View File

@ -64,7 +64,7 @@ namespace ANX.PlatformSystem.Windows
#endregion
#region CreateMediaPlayer (TODO)
public INativeMediaLibrary CreateMediaPlayer()
public INativeMediaLibrary CreateMediaLibrary()
{
throw new NotImplementedException();
}