diff --git a/Vocaluxe/Base/CGame.cs b/Vocaluxe/Base/CGame.cs index 46df686f..9c53cd76 100644 --- a/Vocaluxe/Base/CGame.cs +++ b/Vocaluxe/Base/CGame.cs @@ -364,13 +364,13 @@ namespace Vocaluxe.Base _LastEvalBeat = RecordedBeat; } - public static void ResetToLastLine(int soundStream, int vidStream) + public static void ResetToLastLine(int soundStream, CVideoStream vidStream) { float[] time = _GetLastSungLineStart(); ResetToTime(time[0], time[1], soundStream, vidStream); } - public static void ResetToTime(float time, float nextStart, int soundStream, int vidStream) + public static void ResetToTime(float time, float nextStart, int soundStream, CVideoStream vidStream) { if (time < 0) time = 0; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index b9d016be..2618e74a 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -282,7 +282,7 @@ namespace Vocaluxe.Base return CTheme.GetSkinTexture(textureName, partyModeID); } - public int GetSkinVideo(string videoName, int partyModeID, bool loop) + public CVideoStream GetSkinVideo(string videoName, int partyModeID, bool loop) { return CTheme.GetSkinVideo(videoName, partyModeID, loop); } @@ -810,44 +810,44 @@ namespace Vocaluxe.Base class CBvideo : IVideo { - public int Load(string videoFileName) + public CVideoStream Load(string videoFileName) { return CVideo.Load(videoFileName); } - public bool Skip(int videoStream, float startPosition, float videoGap) + public bool Skip(CVideoStream stream, float startPosition, float videoGap) { - return CVideo.Skip(videoStream, startPosition, videoGap); + return CVideo.Skip(stream, startPosition, videoGap); } - public bool GetFrame(int videoStream, ref CTextureRef videoTexture, float time, out float videoTime) + public bool GetFrame(CVideoStream stream, float time) { - return CVideo.GetFrame(videoStream, ref videoTexture, time, out videoTime); + return CVideo.GetFrame(stream, time); } - public bool IsFinished(int videoStream) + public bool IsFinished(CVideoStream stream) { - return CVideo.Finished(videoStream); + return CVideo.Finished(stream); } - public bool Close(int videoStream) + public void Close(ref CVideoStream stream) { - return CVideo.Close(videoStream); + CVideo.Close(ref stream); } - public void SetLoop(int streamID, bool loop = true) + public void SetLoop(CVideoStream stream, bool loop = true) { - CVideo.SetLoop(streamID, loop); + CVideo.SetLoop(stream, loop); } - public void Pause(int streamID) + public void Pause(CVideoStream stream) { - CVideo.Pause(streamID); + CVideo.Pause(stream); } - public void Resume(int streamID) + public void Resume(CVideoStream stream) { - CVideo.Resume(streamID); + CVideo.Resume(stream); } } diff --git a/Vocaluxe/Base/CSkin.cs b/Vocaluxe/Base/CSkin.cs index 2937f3d9..b5ac1f8f 100644 --- a/Vocaluxe/Base/CSkin.cs +++ b/Vocaluxe/Base/CSkin.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Xml; +using Vocaluxe.Lib.Video; using VocaluxeLib; using VocaluxeLib.Draw; @@ -14,9 +15,10 @@ namespace Vocaluxe.Base public CTextureRef Texture; } - class CVideoSkinElement : CSkinElement + class CVideoSkinElement { - public int VideoStream = -1; + public string Value; + public CVideoStream VideoStream; } class CSkin @@ -123,8 +125,7 @@ namespace Vocaluxe.Base foreach (CVideoSkinElement vsk in VideoList.Values) { - CVideo.Close(vsk.VideoStream); - CDraw.RemoveTexture(ref vsk.Texture); + CVideo.Close(ref vsk.VideoStream); } SkinList.Clear(); VideoList.Clear(); @@ -272,19 +273,19 @@ namespace Vocaluxe.Base return false; } - public int GetVideo(string videoName, bool loop = true) + public CVideoStream GetVideo(string videoName, bool loop = true) { CVideoSkinElement sk; if (VideoList.TryGetValue(videoName, out sk)) { - if (sk.VideoStream == -1) + if (sk.VideoStream == null || sk.VideoStream.IsClosed()) { sk.VideoStream = CVideo.Load(Path.Combine(_Folder, sk.Value)); CVideo.SetLoop(sk.VideoStream, loop); } return sk.VideoStream; } - return -1; + return null; } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 82a1c064..783bfbb5 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -21,6 +21,7 @@ using System.IO; using System.Linq; using System.Xml; using Vocaluxe.Base.Fonts; +using Vocaluxe.Lib.Video; using VocaluxeLib; using VocaluxeLib.Draw; @@ -82,6 +83,11 @@ namespace Vocaluxe.Base return LoadSkins() && LoadTheme(); } + public static void Close() + { + UnloadSkins(); + } + public static bool LoadSkins() { //Fail if loading of any skin failed or no skin was loaded @@ -380,10 +386,10 @@ namespace Vocaluxe.Base return null; } - public static int GetSkinVideo(string videoName, int partyModeID, bool loop = true) + public static CVideoStream GetSkinVideo(string videoName, int partyModeID, bool loop = true) { CSkin skin = _GetSkin(partyModeID); - return skin == null ? -1 : skin.GetVideo(videoName, loop); + return skin == null ? null : skin.GetVideo(videoName, loop); } #endregion Theme and Skin index handling diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 9b127eae..ddd814e8 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -17,7 +17,6 @@ using Vocaluxe.Lib.Video; using VocaluxeLib; -using VocaluxeLib.Draw; namespace Vocaluxe.Base { @@ -60,49 +59,51 @@ namespace Vocaluxe.Base return _VideoDecoder.GetNumStreams(); } - public static int Load(string videoFileName) + public static CVideoStream Load(string videoFileName) { return _VideoDecoder.Load(videoFileName); } - public static bool Close(int streamID) + public static void Close(ref CVideoStream stream) { - return _VideoDecoder.Close(streamID); + //Check for null because the videostreams may close themselves on destroy (GC) + if (_VideoDecoder != null) + _VideoDecoder.Close(ref stream); } - public static float GetLength(int streamID) + public static float GetLength(CVideoStream stream) { - return _VideoDecoder.GetLength(streamID); + return _VideoDecoder.GetLength(stream); } - public static bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime) + public static bool GetFrame(CVideoStream stream, float time) { - return _VideoDecoder.GetFrame(streamID, ref frame, time, out videoTime); + return _VideoDecoder.GetFrame(stream, time); } - public static bool Skip(int streamID, float start, float gap) + public static bool Skip(CVideoStream stream, float start, float gap) { - return _VideoDecoder.Skip(streamID, start, gap); + return _VideoDecoder.Skip(stream, start, gap); } - public static void SetLoop(int streamID, bool loop) + public static void SetLoop(CVideoStream stream, bool loop) { - _VideoDecoder.SetLoop(streamID, loop); + _VideoDecoder.SetLoop(stream, loop); } - public static void Pause(int streamID) + public static void Pause(CVideoStream stream) { - _VideoDecoder.Pause(streamID); + _VideoDecoder.Pause(stream); } - public static void Resume(int streamID) + public static void Resume(CVideoStream stream) { - _VideoDecoder.Resume(streamID); + _VideoDecoder.Resume(stream); } - public static bool Finished(int streamID) + public static bool Finished(CVideoStream stream) { - return _VideoDecoder.Finished(streamID); + return _VideoDecoder.Finished(stream); } public static void Update() diff --git a/Vocaluxe/Base/CVideoPlayer.cs b/Vocaluxe/Base/CVideoPlayer.cs index 6cd0b552..3b4bd78b 100644 --- a/Vocaluxe/Base/CVideoPlayer.cs +++ b/Vocaluxe/Base/CVideoPlayer.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using Vocaluxe.Lib.Video; using VocaluxeLib; using VocaluxeLib.Draw; @@ -6,8 +7,7 @@ namespace Vocaluxe.Base { class CVideoPlayer { - private CTextureRef _VideoTexture; - private int _VideoStream; + private CVideoStream _VideoStream; private readonly Stopwatch _VideoTimer = new Stopwatch(); private bool _Finished; private bool _Loaded; @@ -57,12 +57,12 @@ namespace Vocaluxe.Base float videoTime = _VideoTimer.ElapsedMilliseconds / 1000f; _Finished = CVideo.Finished(_VideoStream); - CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); + CVideo.GetFrame(_VideoStream, videoTime); } - if (_VideoTexture == null) + if (_VideoStream.Texture == null) return; - CDraw.DrawTexture(_VideoTexture, CSettings.RenderRect, EAspect.Crop); + CDraw.DrawTexture(_VideoStream.Texture, CSettings.RenderRect, EAspect.Crop); } public void PreLoad() @@ -71,10 +71,9 @@ namespace Vocaluxe.Base if (paused) CVideo.Resume(_VideoStream); float videoTime = 0f; - while (_VideoTexture == null && videoTime < 1f) + while (_VideoStream.Texture == null && videoTime < 1f) { - float dummy; - CVideo.GetFrame(_VideoStream, ref _VideoTexture, 0, out dummy); + CVideo.GetFrame(_VideoStream, 0); videoTime += 0.05f; } if (paused) @@ -83,8 +82,7 @@ namespace Vocaluxe.Base public void Close() { - CVideo.Close(_VideoStream); - CDraw.RemoveTexture(ref _VideoTexture); + CVideo.Close(ref _VideoStream); _Loaded = false; _Finished = false; _VideoTimer.Reset(); diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index 045a6344..48e6954e 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -17,7 +17,7 @@ using System.Collections.Generic; using Vocaluxe.Lib.Video.Acinerella; -using VocaluxeLib.Draw; +using VocaluxeLib; namespace Vocaluxe.Lib.Video { @@ -39,7 +39,7 @@ namespace Vocaluxe.Lib.Video _Decoder.Clear(); } - public int Load(string videoFileName) + public CVideoStream Load(string videoFileName) { var decoder = new CDecoder(); @@ -47,21 +47,23 @@ namespace Vocaluxe.Lib.Video { int id = _LastID++; _Decoder.Add(id, decoder); - return id; + return new CVideoStream(id); } - return -1; + return null; } - public bool Close(int streamID) + public void Close(ref CVideoStream stream) { + if (stream == null) + return; CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) { decoder.Close(); - _Decoder.Remove(streamID); - return true; + _Decoder.Remove(stream.ID); } - return false; + stream.SetClosed(); + stream = null; } public int GetNumStreams() @@ -69,60 +71,70 @@ namespace Vocaluxe.Lib.Video return _Decoder.Count; } - public bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime) + public bool GetFrame(CVideoStream stream, float time) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) - return decoder.GetFrame(ref frame, time, out videoTime); - videoTime = 0; + if (_TryGetDecoder(stream, out decoder)) + return decoder.GetFrame(ref stream.Texture, time, out stream.VideoTime); + stream.VideoTime = 0; return false; } - public float GetLength(int streamID) + public float GetLength(CVideoStream stream) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) return decoder.Length; return 0f; } - public bool Skip(int streamID, float start, float gap) + public bool Skip(CVideoStream stream, float start, float gap) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) return decoder.Skip(start, gap); return false; } - public void SetLoop(int streamID, bool loop) + public void SetLoop(CVideoStream stream, bool loop) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) decoder.Loop = loop; } - public void Pause(int streamID) + public void Pause(CVideoStream stream) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) decoder.Paused = true; } - public void Resume(int streamID) + public void Resume(CVideoStream stream) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) decoder.Paused = false; } - public bool Finished(int streamID) + public bool Finished(CVideoStream stream) { CDecoder decoder; - if (_Decoder.TryGetValue(streamID, out decoder)) + if (_TryGetDecoder(stream, out decoder)) return decoder.Finished; return true; } public void Update() {} + + private bool _TryGetDecoder(CVideoStream stream, out CDecoder decoder) + { + if (stream == null) + { + decoder = null; + return false; + } + return _Decoder.TryGetValue(stream.ID, out decoder); + } } } \ No newline at end of file diff --git a/Vocaluxe/Lib/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index ebf5e575..205b157c 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -15,7 +15,7 @@ // along with Vocaluxe. If not, see . #endregion -using VocaluxeLib.Draw; +using VocaluxeLib; namespace Vocaluxe.Lib.Video { @@ -36,15 +36,14 @@ namespace Vocaluxe.Lib.Video /// Loads the file with the given file path. /// /// Absolute file path of the video file - /// StreamID >=0 on success or -1 on failure - int Load(string videoFileName); + /// stream >=0 on success or -1 on failure + CVideoStream Load(string videoFileName); /// /// Closes the stream with the given ID /// - /// ID of the stream - /// true if stream was closed, false if stream doesn't exist or already closed - bool Close(int streamID); + /// ID of the stream + void Close(ref CVideoStream stream); /// /// Gets the number of streams currently active @@ -55,60 +54,56 @@ namespace Vocaluxe.Lib.Video /// /// Gets the length of the video in s /// - /// Id of the stream + /// Id of the stream /// Length of the video in s - float GetLength(int streamID); + float GetLength(CVideoStream stream); /// /// Gets a frame of the video and sets the current video time - /// - /// Id of the stream - /// - /// Reference to already initialized video texture (from previous calls). If null, one will be created.
/// Returns the current video frame which might be outdated if time != current (internal) video position or unchanged (even null) if none is available. - /// + ///
+ /// Id of the stream /// /// The position in s of the video you want to get a frame of. If != current (internal) video position, it will seek to get to right position.
/// Note:Will be ignored for looped playback! /// - /// The actual position in s of the returned frame. Should be ~ time+VideoGap /// True if frame is valid, false: frame and videoTime might be unchanged or invalid - bool GetFrame(int streamID, ref CTextureRef frame, float time, out float videoTime); + bool GetFrame(CVideoStream stream, float time); /// /// Seeks to given position /// - /// Id of the stream + /// Id of the stream /// Position to seek to /// New video gap -> Actual position will be start+gap /// True on success - bool Skip(int streamID, float start, float gap); + bool Skip(CVideoStream stream, float start, float gap); /// /// Set if the video should be looped /// - /// Id of the stream + /// Id of the stream /// True if it should be looped - void SetLoop(int streamID, bool loop); + void SetLoop(CVideoStream stream, bool loop); /// /// Pauses the video (no new frames will be decoded) /// - /// Id of the stream - void Pause(int streamID); + /// Id of the stream + void Pause(CVideoStream stream); /// /// Resumes a paused video /// - /// Id of the stream - void Resume(int streamID); + /// Id of the stream + void Resume(CVideoStream stream); /// /// Check if the given video is finished /// - /// Id of the stream + /// Id of the stream /// True if all frames are shown - bool Finished(int streamID); + bool Finished(CVideoStream stream); /// /// Do a step of the decoder in unthreaded decoders. Should be called once every frame. diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index 9b1969f1..2236aa0a 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -263,6 +263,7 @@ namespace Vocaluxe CController.Close(); CVocaluxeServer.Close(); CGraphics.Close(); + CTheme.Close(); CCover.Close(); CBackgroundMusic.Close(); CWebcam.Close(); diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index e3f1f525..d3561f44 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -23,6 +23,7 @@ using System.Linq; using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Base.Fonts; +using Vocaluxe.Lib.Video; using VocaluxeLib; using VocaluxeLib.Draw; using VocaluxeLib.Menu; @@ -96,9 +97,8 @@ namespace Vocaluxe.Screens private float _Length = -1f; //private int _NextStream = -1; private const float _Volume = 100f; - private int _CurrentVideo = -1; + private CVideoStream _CurrentVideo; private EAspect _VideoAspect = EAspect.Crop; - private CTextureRef _CurrentVideoTexture; private CTextureRef _CurrentWebcamFrameTexture; private CTextureRef _Background; @@ -400,10 +400,9 @@ namespace Vocaluxe.Screens _Texts[_TextScores[p, CGame.NumPlayer - 1]].Text = CGame.Players[p].Points.ToString(fmtString); } - if (_CurrentVideo != -1 && !_FadeOut && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON) + if (_CurrentVideo != null && !_FadeOut && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON) { - float vtime; - CVideo.GetFrame(_CurrentVideo, ref _CurrentVideoTexture, _CurrentTime, out vtime); + CVideo.GetFrame(_CurrentVideo, _CurrentTime); } if (_Webcam) @@ -418,8 +417,7 @@ namespace Vocaluxe.Screens _FadeOut = false; - _CurrentVideo = -1; - _CurrentVideoTexture = null; + _CurrentVideo = null; _CurrentWebcamFrameTexture = null; _CurrentBeat = -100; _CurrentTime = 0f; @@ -464,9 +462,9 @@ namespace Vocaluxe.Screens { CTextureRef background; var aspect = EAspect.Crop; - if (_CurrentVideo != -1 && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam) + if (_CurrentVideo != null && CConfig.VideosInSongs == EOffOn.TR_CONFIG_ON && !_Webcam) { - background = _CurrentVideoTexture; + background = _CurrentVideo.Texture; aspect = _VideoAspect; } else if (_Webcam) @@ -557,11 +555,9 @@ namespace Vocaluxe.Screens _CurrentStream = -1; } CRecord.Stop(); - if (_CurrentVideo != -1) + if (_CurrentVideo != null) { - CVideo.Close(_CurrentVideo); - _CurrentVideo = -1; - CDraw.RemoveTexture(ref _CurrentVideoTexture); + CVideo.Close(ref _CurrentVideo); } CDraw.RemoveTexture(ref _Background); @@ -624,8 +620,6 @@ namespace Vocaluxe.Screens } CGame.ResetPlayer(); - CDraw.RemoveTexture(ref _CurrentVideoTexture); - if (!String.IsNullOrEmpty(song.VideoFileName)) { _CurrentVideo = CVideo.Load(Path.Combine(song.Folder, song.VideoFileName)); diff --git a/VocaluxeLib/CVideoStream.cs b/VocaluxeLib/CVideoStream.cs new file mode 100644 index 00000000..662aa495 --- /dev/null +++ b/VocaluxeLib/CVideoStream.cs @@ -0,0 +1,45 @@ +using VocaluxeLib.Draw; + +namespace VocaluxeLib +{ + public class CVideoStream + { + public int ID { get; private set; } + public CTextureRef Texture; + /// The actual position in s of the returned frame. Should be ~ time+VideoGap + public float VideoTime; + + public CVideoStream(int id) + { + ID = id; + } + + ~CVideoStream() + { + if (ID >= 0) + { + CVideoStream tmp = this; + CBase.Video.Close(ref tmp); + } + } + + /// + /// Should only be used by video decoders
+ /// Set's this stream to closed state and frees the texture + ///
+ public void SetClosed() + { + ID = -1; + CBase.Drawing.RemoveTexture(ref Texture); + } + + /// + /// Returns true if the video stream is closed + /// + /// + public bool IsClosed() + { + return ID < 0; + } + } +} \ No newline at end of file diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index ad1226ed..c473b8ba 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -103,7 +103,7 @@ namespace VocaluxeLib string GetThemeScreensPath(int partyModeID); int GetSkinIndex(int partyModeID); CTextureRef GetSkinTexture(string textureName, int partyModeID); - int GetSkinVideo(string videoName, int partyModeID, bool loop); + CVideoStream GetSkinVideo(string videoName, int partyModeID, bool loop); bool GetColor(string colorName, int partyModeID, out SColorF color); SColorF GetPlayerColor(int playerNr); @@ -264,14 +264,14 @@ namespace VocaluxeLib public interface IVideo { - int Load(string videoFileName); - bool Skip(int streamID, float startPosition, float videoGap); - bool GetFrame(int streamID, ref CTextureRef videoTexture, float time, out float videoTime); - bool IsFinished(int streamID); - bool Close(int streamID); - void SetLoop(int streamID, bool loop = true); - void Resume(int streamID); - void Pause(int streamID); + CVideoStream Load(string videoFileName); + bool Skip(CVideoStream stream, float startPosition, float videoGap); + bool GetFrame(CVideoStream stream, float time); + bool IsFinished(CVideoStream stream); + void Close(ref CVideoStream stream); + void SetLoop(CVideoStream stream, bool loop = true); + void Resume(CVideoStream stream); + void Pause(CVideoStream stream); } public interface ISound diff --git a/VocaluxeLib/Menu/CBackground.cs b/VocaluxeLib/Menu/CBackground.cs index fe6f2f97..4e13179f 100644 --- a/VocaluxeLib/Menu/CBackground.cs +++ b/VocaluxeLib/Menu/CBackground.cs @@ -16,7 +16,6 @@ #endregion using System; -using System.Xml; using System.Xml.Serialization; using System.Diagnostics; using System.Collections.Generic; @@ -54,8 +53,7 @@ namespace VocaluxeLib.Menu private readonly Stopwatch _SlideShowTimer = new Stopwatch(); private readonly List _SlideShowTextures = new List(); - private int _VideoStream = -1; - private CTextureRef _VidTex; + private CVideoStream _VideoStream; public SColorF Color; public bool ThemeLoaded @@ -136,13 +134,13 @@ namespace VocaluxeLib.Menu public void Resume() { - if (_VideoStream != -1) + if (_VideoStream != null) CBase.Video.Resume(_VideoStream); } public void Pause() { - if (_VideoStream != -1) + if (_VideoStream != null) CBase.Video.Pause(_VideoStream); } @@ -176,9 +174,7 @@ namespace VocaluxeLib.Menu public void UnloadTextures() { _SlideShowTextures.Clear(); - CBase.Video.Close(_VideoStream); - _VideoStream = -1; - CBase.Drawing.RemoveTexture(ref _VidTex); + CBase.Video.Close(ref _VideoStream); } public void LoadTextures() @@ -299,11 +295,10 @@ namespace VocaluxeLib.Menu private bool _DrawVideo() { - float time; - CBase.Video.GetFrame(_VideoStream, ref _VidTex, 0, out time); - if (_VidTex != null) + CBase.Video.GetFrame(_VideoStream, _VideoStream.VideoTime); + if (_VideoStream.Texture != null) { - CBase.Drawing.DrawTexture(_VidTex, _GetDrawRect(), EAspect.Crop); + CBase.Drawing.DrawTexture(_VideoStream.Texture, _GetDrawRect(), EAspect.Crop); return true; } return false; diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index d90eb1b6..f978fcd7 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; using VocaluxeLib.Draw; using VocaluxeLib.Songs; @@ -12,8 +9,7 @@ namespace VocaluxeLib.Utils.Player { private CSong _Song; private bool _VideoEnabled; - private int _Video = -1; - private CTextureRef _CurrentVideoTexture; + private CVideoStream _Video; private CFading _VideoFading; public bool VideoEnabled @@ -26,12 +22,8 @@ namespace VocaluxeLib.Utils.Player _VideoEnabled = value; if (_VideoEnabled) _LoadVideo(); - else if (_Video != -1) - { - CBase.Video.Close(_Video); - CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } + else if (_Video != null) + CBase.Video.Close(ref _Video); } } public int SongID @@ -82,19 +74,18 @@ namespace VocaluxeLib.Utils.Player public CTextureRef GetVideoTexture() { - if (_Video == -1 || _Song == null) + if (_Video == null || _Song == null) return null; - float vtime; - if (CBase.Video.GetFrame(_Video, ref _CurrentVideoTexture, CBase.Sound.GetPosition(_StreamID), out vtime)) + if (CBase.Video.GetFrame(_Video, CBase.Sound.GetPosition(_StreamID))) { if (_VideoFading != null) { bool finished; - _CurrentVideoTexture.Color.A = _VideoFading.GetValue(out finished); + _Video.Texture.Color.A = _VideoFading.GetValue(out finished); if (finished) _VideoFading = null; } - return _CurrentVideoTexture; + return _Video.Texture; } return null; } @@ -108,7 +99,7 @@ namespace VocaluxeLib.Utils.Player _Song = song; - base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false); + Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); _LoadVideo(); if (autoplay) @@ -122,7 +113,7 @@ namespace VocaluxeLib.Utils.Player Stop(); - base.Load(file, position, autoplay); + Load(file, position, autoplay); } public new void Play() @@ -138,22 +129,18 @@ namespace VocaluxeLib.Utils.Player _Song = null; - if (_Video != -1) - { - CBase.Video.Close(_Video); - CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } + if (_Video != null) + CBase.Video.Close(ref _Video); } public new void TogglePause() { - if (IsPlaying && _Video != -1) + if (IsPlaying && _Video != null) { CBase.Video.Pause(_Video); CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); } - else if (_Video != -1) + else if (_Video != null) CBase.Video.Resume(_Video); base.TogglePause(); } @@ -164,7 +151,7 @@ namespace VocaluxeLib.Utils.Player return; string videoFilePath = Path.Combine(_Song.Folder, _Song.VideoFileName); - if (_Video != -1 || String.IsNullOrEmpty(videoFilePath)) + if (_Video != null || String.IsNullOrEmpty(videoFilePath)) return; _Video = CBase.Video.Load(videoFilePath); CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture diff --git a/VocaluxeLib/VocaluxeLib.csproj b/VocaluxeLib/VocaluxeLib.csproj index 11f27989..4e3f0354 100644 --- a/VocaluxeLib/VocaluxeLib.csproj +++ b/VocaluxeLib/VocaluxeLib.csproj @@ -78,6 +78,7 @@ +