Merge pull request #4 from xDarkice/master
Play Background Music in a List
This commit is contained in:
commit
ede3648f2f
2 files changed
+48
-9
No files matched your search
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using Vocaluxe.Base;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Vocaluxe.Base
|
||||
{
|
||||
@@ -11,6 +12,10 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
private static CHelper Helper = new CHelper();
|
||||
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()
|
||||
{
|
||||
@@ -24,33 +29,66 @@ namespace Vocaluxe.Base
|
||||
{
|
||||
_BackgroundMusicStreams.Add(CSound.Load(file));
|
||||
}
|
||||
|
||||
if(_BackgroundMusicStreams.Count > 0)
|
||||
_CurrentMusicStream = _BackgroundMusicStreams[0];
|
||||
}
|
||||
|
||||
public static void Play()
|
||||
{
|
||||
if (CConfig.BackgroundMusic == EOffOn.TR_CONFIG_ON)
|
||||
{
|
||||
foreach (int i in _BackgroundMusicStreams)
|
||||
if(_BackgroundMusicStreams.Count == 1)
|
||||
{
|
||||
CSound.Fade(i, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
CSound.Play(i, true);
|
||||
CSound.Fade(_BackgroundMusicStreams[0], CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
CSound.Play(_BackgroundMusicStreams[0], true);
|
||||
}
|
||||
else if (_BackgroundMusicStreams.Count > 1)
|
||||
{
|
||||
CSound.Fade(_CurrentMusicStream, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
CSound.Play(_CurrentMusicStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
foreach (int i in _BackgroundMusicStreams)
|
||||
{
|
||||
CSound.FadeAndStop(i, CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
}
|
||||
if(_BackgroundMusicStreams.Count > 0)
|
||||
CSound.FadeAndStop(_BackgroundMusicStreams[_CurrentStreamListIndex], CConfig.BackgroundMusicVolume, CConfig.FadeTime);
|
||||
}
|
||||
|
||||
public static void Pause()
|
||||
{
|
||||
foreach (int i in _BackgroundMusicStreams)
|
||||
if (_BackgroundMusicStreams.Count > 0)
|
||||
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();
|
||||
|
||||
CSound.Update();
|
||||
CBackgroundMusic.Update();
|
||||
|
||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing)
|
||||
CSongs.LoadCover(30L);
|
||||
|
||||
Reference in new issue
Block a user