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