From 1ddcf765f335ab713643f45a12d67a2117e2daf4 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sat, 25 Jan 2020 08:33:11 +0100 Subject: [PATCH] Change: Only touch the preview player if necessary Complete change of LoadPreview() to prevent touching the preview player, if we don't want to change anything. Maybe this change break something, but after 2 hours of testing with different settings, everything seems to work here. --- Vocaluxe/Base/CBackgroundMusic.cs | 61 ++++++++++--------------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 5050b408..44295ce2 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -316,56 +316,33 @@ namespace Vocaluxe.Base CSound.SetGlobalVolume(CConfig.PreviewMusicVolume); } + //Change song position only if song is changed or near to end bool songChanged = _CurPlayer.SongID != song.ID; + if (!songChanged && _CurPlayer.Position + 30 < _CurPlayer.Length) + return; _PreviewPlayer.Load(song); - - //Change song position only if song is changed or near to end - if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length || _PreviewStartHelperTask == null) + lock (_PreviewStartHelperTaskLock) { - lock (_PreviewStartHelperTaskLock) + _PreviewStartHelperTask = new Task(() => { - _PreviewStartHelperTask = new Task(() => - { - float length = _PreviewPlayer.Length; - if (length < 1) - length = 30; // If length is unknow or invalid assume a length of 30s + float length = _PreviewPlayer.Length; + if (length < 1) + length = 30; // If length is unknow or invalid assume a length of 30s - if (start < 0) - start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; - if (start > length - 5f) - start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - if (start >= 0.5f) - start -= 0.5f; + if (start < 0) + start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; + if (start > length - 5f) + start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + if (start >= 0.5f) + start -= 0.5f; - _PreviewPlayer.Position = start; - Play(); - }); - } - _CurPlayer = _PreviewPlayer; + _PreviewPlayer.Position = start; + Play(); + }); } - else - { - if (_PreviewStartHelperTask != null) - { - lock (_PreviewStartHelperTaskLock) - { - // Recheck the condition as it cloud have change before we got the lock - if (_PreviewStartHelperTask != null) - { - _PreviewStartHelperTask = null; - } - } - } - _PreviewPlayer.Position = _CurPlayer.Position; - _CurPlayer = _PreviewPlayer; - Play(); - } - - - - + _CurPlayer = _PreviewPlayer; } public static void StopPreview() @@ -460,4 +437,4 @@ namespace Vocaluxe.Base return _BGMusicFiles.Contains(element); } } -} \ No newline at end of file +}