Merge pull request #195 from lukeIam/previewStartBug
Fix preview start bug on top of PR #191
This commit is contained in:
commit
d9ef14be0b
3 files changed
+37
-14
No files matched your search
@@ -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,10 @@ namespace Vocaluxe.Base
|
|||||||
private static bool _BackgroundMusicAdded;
|
private static bool _BackgroundMusicAdded;
|
||||||
private static bool _Disabled;
|
private static bool _Disabled;
|
||||||
|
|
||||||
|
private static Task _PreviewStartHelperTask;
|
||||||
|
private static int _PreviewStartWaitCounter;
|
||||||
|
private const int _PreviewStartWaitMaxTries = 10;
|
||||||
|
|
||||||
public static bool VideoEnabled
|
public static bool VideoEnabled
|
||||||
{
|
{
|
||||||
get { return _CurPlayer.VideoEnabled; }
|
get { return _CurPlayer.VideoEnabled; }
|
||||||
@@ -249,6 +254,14 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
public static void Update()
|
public static void Update()
|
||||||
{
|
{
|
||||||
|
if (_PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries))
|
||||||
|
{
|
||||||
|
_PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext());
|
||||||
|
_PreviewStartHelperTask.Dispose();
|
||||||
|
_PreviewStartHelperTask = null;
|
||||||
|
_PreviewStartWaitCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!IsPlaying)
|
if (!IsPlaying)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -299,31 +312,41 @@ namespace Vocaluxe.Base
|
|||||||
bool songChanged = _CurPlayer.SongID != song.ID;
|
bool songChanged = _CurPlayer.SongID != song.ID;
|
||||||
|
|
||||||
_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()
|
||||||
|
|||||||
@@ -684,7 +684,7 @@ namespace Vocaluxe.Screens
|
|||||||
{
|
{
|
||||||
int song = _SongMenu.GetSelectedSongNr();
|
int song = _SongMenu.GetSelectedSongNr();
|
||||||
if (song >= 0 && song < CSongs.VisibleSongs.Count)
|
if (song >= 0 && song < CSongs.VisibleSongs.Count)
|
||||||
selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title + " ( "+(song+1)+" / "+CSongs.NumAllSongs+" )";
|
selectionText = CSongs.VisibleSongs[song].Artist + " - " + CSongs.VisibleSongs[song].Title + " ( "+(song+1)+" / "+CSongs.NumSongsVisible+" )";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ namespace VocaluxeLib.Menu.SongMenu
|
|||||||
if (song == null)
|
if (song == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CBase.BackgroundMusic.LoadPreview(song);
|
CBase.BackgroundMusic.LoadPreview(song, song.Preview.StartTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _ResetPreview(bool playBGagain = true)
|
protected void _ResetPreview(bool playBGagain = true)
|
||||||
|
|||||||
Reference in new issue
Block a user