diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 711c88bb..6f050db8 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -51,8 +51,13 @@ namespace Vocaluxe.Base public static bool VideoEnabled { - get { return _SongPlayer.VideoEnabled; } - set { _SongPlayer.VideoEnabled = value; } + get { return _PlaysPreview ? _PreviewPlayer.VideoEnabled : _SongPlayer.VideoEnabled; } + set { + if(_PlaysPreview) + _PreviewPlayer.VideoEnabled = value; + else + _SongPlayer.VideoEnabled = value; + } } public static bool CanSing { get { return _BGMusicFiles.Contains(_CurrentPlaylistElement) ? false : _SongPlayer.CanSing; } } @@ -152,8 +157,8 @@ namespace Vocaluxe.Base public static void Close() { - _SongPlayer.Close(); - _PreviewPlayer.Close(); + _SongPlayer.Stop(); + _PreviewPlayer.Stop(); _BGMusicFiles.Clear(); _NotPlayedFiles.Clear(); @@ -168,7 +173,7 @@ namespace Vocaluxe.Base return; if (_PlaysPreview) - _PreviewPlayer.TogglePause(); + _PreviewPlayer.Play(); else if (_SongPlayer.SongLoaded) //Resume @@ -338,7 +343,7 @@ namespace Vocaluxe.Base public static void StopPreview() { - _PreviewPlayer.Close(); + _PreviewPlayer.Stop(); _PlaysPreview = false; } @@ -350,7 +355,7 @@ namespace Vocaluxe.Base Debug.Assert(_CurrentPlaylistElement != null); //If current song same as loaded restart only - if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID) + if (_CurrentPlaylistElement.SongID == _SongPlayer.SongID && _SongPlayer.SongLoaded) _SongPlayer.Play(); //otherwhise load diff --git a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs index 9ffe1779..208fc630 100644 --- a/Vocaluxe/Screens/CPopupScreenPlayerControl.cs +++ b/Vocaluxe/Screens/CPopupScreenPlayerControl.cs @@ -168,6 +168,17 @@ namespace Vocaluxe.Screens return true; } + public override void OnShow() + { + base.OnShow(); + _Buttons[_ButtonNext].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPause].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPlay].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonPrevious].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonRepeat].Visible = !CBackgroundMusic.IsPlayingPreview; + _Buttons[_ButtonSing].Visible = !CBackgroundMusic.IsPlayingPreview; + } + public override bool UpdateGame() { _Statics[_StaticCover].Visible = !_VideoPreviewInt || !CBackgroundMusic.SongHasVideo; diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs index 9a11dde7..b4d0cff4 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs @@ -341,7 +341,7 @@ namespace VocaluxeLib.Menu.SongMenu public virtual void Init() { - _ResetPreview(); + _ResetPreview(false); _Initialized = true; } @@ -482,7 +482,7 @@ namespace VocaluxeLib.Menu.SongMenu if (categoryNr >= CBase.Songs.GetNumCategories()) return; - _ResetPreview(); + _ResetPreview(false); CBase.Songs.SetCategory(categoryNr); } @@ -511,9 +511,12 @@ namespace VocaluxeLib.Menu.SongMenu CBase.BackgroundMusic.LoadPreview(song); } - protected void _ResetPreview() + protected void _ResetPreview(bool playBGagain = true) { - CBase.BackgroundMusic.Stop(); + CBase.BackgroundMusic.StopPreview(); + + if (playBGagain) + CBase.BackgroundMusic.Play(); //Make sure we don't have a preview here otherwise a change won't be recognized //(e.g. leave a category with one song and set preview to 0 --> previewOld=previewNew=0 --> No change --> Old data shown diff --git a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs index f473ead7..b33a1d16 100644 --- a/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs +++ b/VocaluxeLib/Menu/SongMenu/CSongMenuTileBoard.cs @@ -467,7 +467,7 @@ namespace VocaluxeLib.Menu.SongMenu _TextBG.Draw(); - CTexture vidtex = CBase.BackgroundMusic.GetVideoTexture(); + CTexture vidtex = CBase.BackgroundMusic.IsPlayingPreview() ? CBase.BackgroundMusic.GetVideoTexture() : null; if (vidtex != null) { diff --git a/VocaluxeLib/Utils/Player/CSongPlayer.cs b/VocaluxeLib/Utils/Player/CSongPlayer.cs index fe2f9bb1..27b13176 100644 --- a/VocaluxeLib/Utils/Player/CSongPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSongPlayer.cs @@ -67,23 +67,6 @@ namespace VocaluxeLib.Utils.Player get { return _StreamID != -1; } } - public float Position - { - get - { - if (_StreamID == -1) - return -1; - return CBase.Sound.GetPosition(_StreamID); - } - set - { - if (_StreamID == -1) - return; - CBase.Sound.SetPosition(_StreamID, value); - CBase.Video.Skip(_Video, value, _Song.VideoGap); - _StartPosition = value; - } - } public CSongPlayer(bool loop = false) : base(loop) { } @@ -124,11 +107,15 @@ namespace VocaluxeLib.Utils.Player if (song == null) return; - Close(); + Stop(); _Song = song; + + base.Load(Path.Combine(song.Folder, song.MP3FileName), position, false); _LoadVideo(); - base.Load(Path.Combine(song.Folder, song.MP3FileName), position, autoplay); + + if (autoplay) + Play(); } public void LoadFile(string file, float position = 0f, bool autoplay = false) @@ -136,36 +123,24 @@ namespace VocaluxeLib.Utils.Player if (String.IsNullOrEmpty(file)) return; - Close(); + Stop(); - _Song = null; base.Load(file, position, autoplay); } - public new void Close() - { - base.Close(); - - if (_Video != -1) - { - CBase.Video.Close(_Video); - CBase.Drawing.RemoveTexture(ref _CurrentVideoTexture); - _Video = -1; - } - } - public new void Play() { - base.Play(); - - if (_VideoEnabled && _Video != -1) - CBase.Video.Resume(_Video); + CBase.Sound.SetPosition(_StreamID, _StartPosition); + CBase.Video.Skip(_Video, _StartPosition, _Song.VideoGap); + TogglePause(); } public new void Stop() { base.Stop(); + _Song = null; + if (_Video != -1) { CBase.Video.Close(_Video); @@ -176,8 +151,7 @@ namespace VocaluxeLib.Utils.Player public new void TogglePause() { - base.TogglePause(); - if (!IsPlaying && _Video != -1) + if (IsPlaying && _Video != -1) { CBase.Video.Pause(_Video); CBase.Video.Skip(_Video, CBase.Sound.GetPosition(_StreamID) + _FadeTime, _Song.VideoGap); @@ -186,6 +160,7 @@ namespace VocaluxeLib.Utils.Player { CBase.Video.Resume(_Video); } + base.TogglePause(); } private void _LoadVideo() @@ -197,8 +172,14 @@ namespace VocaluxeLib.Utils.Player if (_Video != -1 || String.IsNullOrEmpty(videoFilePath)) return; _Video = CBase.Video.Load(videoFilePath); - CBase.Video.Skip(_Video, 0f, _Song.VideoGap + _StartPosition); //Use gap, otherwhise we will overwrite position in GetVideoTexture + CBase.Video.Skip(_Video, 0f, _Song.VideoGap); //Use gap, otherwhise we will overwrite position in GetVideoTexture _VideoFading = new CFading(0f, 1f, 3f); + + if (IsPlaying) + { + CBase.Video.Skip(_Video, Position, _Song.VideoGap); + CBase.Video.Resume(_Video); + } } } } diff --git a/VocaluxeLib/Utils/Player/CSoundPlayer.cs b/VocaluxeLib/Utils/Player/CSoundPlayer.cs index a3a86f51..b2b19b9e 100644 --- a/VocaluxeLib/Utils/Player/CSoundPlayer.cs +++ b/VocaluxeLib/Utils/Player/CSoundPlayer.cs @@ -28,7 +28,6 @@ namespace VocaluxeLib.Utils.Player set { if(_StreamID == -1) return; - CBase.Sound.SetPosition(_StreamID, value); _StartPosition = value; } get { @@ -73,8 +72,6 @@ namespace VocaluxeLib.Utils.Player if (IsPlaying) Stop(); - Close(); - _StreamID = CBase.Sound.Load(file, false, true); if (position > 0f) Position = position; @@ -115,7 +112,9 @@ namespace VocaluxeLib.Utils.Player if (_StreamID == -1 || !IsPlaying) return; - CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Stop); + CBase.Sound.Fade(_StreamID, 0f, _FadeTime, EStreamAction.Close); + _StreamID = -1; + IsPlaying = false; } @@ -139,16 +138,6 @@ namespace VocaluxeLib.Utils.Player } - public void Close() - { - if (_StreamID == -1) - return; - - CBase.Sound.Close(_StreamID); - _StreamID = -1; - IsPlaying = false; - } - private void _ApplyVolume() { if (_StreamID == -1)