Merge pull request #195 from lukeIam/previewStartBug

Fix preview start bug on top of PR #191
This commit is contained in:
Florian Küpper committed 2016-02-02 23:09:10 +01:00
commit d9ef14be0b
3 files changed
+37 -14

No files matched your search

+35 -12
View File
@@ -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,10 @@ namespace Vocaluxe.Base
private static bool _BackgroundMusicAdded;
private static bool _Disabled;
private static Task _PreviewStartHelperTask;
private static int _PreviewStartWaitCounter;
private const int _PreviewStartWaitMaxTries = 10;
public static bool VideoEnabled
{
get { return _CurPlayer.VideoEnabled; }
@@ -249,6 +254,14 @@ namespace Vocaluxe.Base
public static void Update()
{
if (_PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries))
{
_PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext());
_PreviewStartHelperTask.Dispose();
_PreviewStartHelperTask = null;
_PreviewStartWaitCounter = 0;
}
if (!IsPlaying)
return;
@@ -299,31 +312,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()
+1 -1
View File
@@ -684,7 +684,7 @@ namespace Vocaluxe.Screens
{
int song = _SongMenu.GetSelectedSongNr();
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
{
@@ -415,7 +415,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (song == null)
return;
CBase.BackgroundMusic.LoadPreview(song);
CBase.BackgroundMusic.LoadPreview(song, song.Preview.StartTime);
}
protected void _ResetPreview(bool playBGagain = true)