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.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;
|
||||
|
||||
@@ -299,31 +309,41 @@ namespace Vocaluxe.Base
|
||||
bool songChanged = _CurPlayer.SongID != song.ID;
|
||||
|
||||
_PreviewPlayer.Load(song);
|
||||
|
||||
|
||||
//Change song position only if song is changed or near to end
|
||||
if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length)
|
||||
{
|
||||
float length = _PreviewPlayer.Length;
|
||||
if (length < 1)
|
||||
length = 30; // If length is unknow or invalid assume a length of 30s
|
||||
PreviewStartHelperTask = new Task(() =>
|
||||
{
|
||||
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;
|
||||
_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