Play Background Music in a List
This commit is contained in:
1 parent
d1d792456b
commit
5fdb3d822c
2 files changed
+44
-9
No files matched your search
@@ -4,6 +4,7 @@ using System.Text;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
using Vocaluxe.Base;
|
using Vocaluxe.Base;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Vocaluxe.Base
|
namespace Vocaluxe.Base
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,10 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
private static CHelper Helper = new CHelper();
|
private static CHelper Helper = new CHelper();
|
||||||
private static List<int> _BackgroundMusicStreams = new List<int>();
|
private static List<int> _BackgroundMusicStreams = new List<int>();
|
||||||
|
private static int _CurrentMusicStream;
|
||||||
|
private static int _CurrentStreamListIndex = 0;
|
||||||
|
private static bool _Fading;
|
||||||
|
private static Stopwatch _FadeTimer = new Stopwatch();
|
||||||
|
|
||||||
public static void init()
|
public static void init()
|
||||||
{
|
{
|
||||||
@@ -24,33 +29,62 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
_BackgroundMusicStreams.Add(CSound.Load(file));
|
_BackgroundMusicStreams.Add(CSound.Load(file));
|
||||||
}
|
}
|
||||||
|
_CurrentMusicStream = _BackgroundMusicStreams[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Play()
|
public static void Play()
|
||||||
{
|
{
|
||||||
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON)
|
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON)
|
||||||
{
|
{
|
||||||
foreach (int i in _BackgroundMusicStreams)
|
if(_BackgroundMusicStreams.Count == 1)
|
||||||
{
|
{
|
||||||
CSound.Fade(i, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
CSound.Fade(_BackgroundMusicStreams[0], CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||||
CSound.Play(i, true);
|
CSound.Play(_BackgroundMusicStreams[0], true);
|
||||||
|
}
|
||||||
|
else if (_BackgroundMusicStreams.Count > 1)
|
||||||
|
{
|
||||||
|
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||||
|
CSound.Play(_CurrentMusicStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Stop()
|
public static void Stop()
|
||||||
{
|
{
|
||||||
foreach (int i in _BackgroundMusicStreams)
|
CSound.FadeAndStop(_BackgroundMusicStreams[_CurrentStreamListIndex], CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||||
{
|
|
||||||
CSound.FadeAndStop(i, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Pause()
|
public static void Pause()
|
||||||
{
|
{
|
||||||
foreach (int i in _BackgroundMusicStreams)
|
CSound.Pause(_BackgroundMusicStreams[_CurrentStreamListIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Update()
|
||||||
|
{
|
||||||
|
if (_BackgroundMusicStreams.Count > 1)
|
||||||
{
|
{
|
||||||
CSound.Pause(i);
|
float timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream);
|
||||||
|
if (_FadeTimer.ElapsedMilliseconds >= CConfig.FadeTime * 1000)
|
||||||
|
{
|
||||||
|
_Fading = false;
|
||||||
|
_FadeTimer.Reset();
|
||||||
|
}
|
||||||
|
if ((timeToPlay <= CConfig.FadeTime) && !_Fading)
|
||||||
|
{
|
||||||
|
_FadeTimer.Start();
|
||||||
|
CSound.Fade(_CurrentMusicStream, 0, CConfig.FadeTime);
|
||||||
|
_CurrentStreamListIndex++;
|
||||||
|
if (_CurrentStreamListIndex + 1 > _BackgroundMusicStreams.Count)
|
||||||
|
{
|
||||||
|
_CurrentStreamListIndex = 0;
|
||||||
|
_CurrentMusicStream = _BackgroundMusicStreams[_CurrentStreamListIndex];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_CurrentMusicStream = _BackgroundMusicStreams[_CurrentStreamListIndex];
|
||||||
|
CSound.SetPosition(_CurrentStreamListIndex, 0);
|
||||||
|
Play();
|
||||||
|
_Fading = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ namespace Vocaluxe.Menu
|
|||||||
Keys.CopyEvents();
|
Keys.CopyEvents();
|
||||||
|
|
||||||
CSound.Update();
|
CSound.Update();
|
||||||
|
CBackgroundMusic.Update();
|
||||||
|
|
||||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing)
|
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing)
|
||||||
CSongs.LoadCover(30L);
|
CSongs.LoadCover(30L);
|
||||||
|
|||||||
Reference in new issue
Block a user