Fix: previewStart is sometimes ignored (closes #188)
This commit is contained in:
1 parent
750b93d6d5
commit
d6fcd7b58c
1 file changed
+22
-2
@@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Songs;
|
||||
using VocaluxeLib.Draw;
|
||||
@@ -47,6 +48,8 @@ namespace Vocaluxe.Base
|
||||
private static bool _BackgroundMusicAdded;
|
||||
private static bool _Disabled;
|
||||
|
||||
private static Task PreviewStartHelperTask;
|
||||
|
||||
public static bool VideoEnabled
|
||||
{
|
||||
get { return _CurPlayer.VideoEnabled; }
|
||||
@@ -249,6 +252,13 @@ namespace Vocaluxe.Base
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
if (PreviewStartHelperTask != null && _PreviewPlayer.Length > 0)
|
||||
{
|
||||
PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext());
|
||||
PreviewStartHelperTask.Dispose();
|
||||
PreviewStartHelperTask = null;
|
||||
}
|
||||
|
||||
if (!IsPlaying)
|
||||
return;
|
||||
|
||||
@@ -300,8 +310,11 @@ namespace Vocaluxe.Base
|
||||
|
||||
_PreviewPlayer.Load(song);
|
||||
|
||||
|
||||
//Change song position only if song is changed or near to end
|
||||
if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length)
|
||||
{
|
||||
PreviewStartHelperTask = new Task(() =>
|
||||
{
|
||||
float length = _PreviewPlayer.Length;
|
||||
if (length < 1)
|
||||
@@ -315,15 +328,22 @@ namespace Vocaluxe.Base
|
||||
start -= 0.5f;
|
||||
|
||||
_PreviewPlayer.Position = start;
|
||||
Play();
|
||||
});
|
||||
_CurPlayer = _PreviewPlayer;
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviewStartHelperTask.Dispose();
|
||||
PreviewStartHelperTask = null;
|
||||
_PreviewPlayer.Position = _CurPlayer.Position;
|
||||
_CurPlayer = _PreviewPlayer;
|
||||
Play();
|
||||
}
|
||||
|
||||
_CurPlayer = _PreviewPlayer;
|
||||
|
||||
Play();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void StopPreview()
|
||||
|
||||
Reference in new issue
Block a user