Play Background Music in a List

This commit is contained in:
Stephan Sundermann committed 2012-02-19 19:46:22 +01:00
1 parent d1d792456b
commit 5fdb3d822c
2 files changed
+44 -9

No files matched your search

+43 -9
View File
@@ -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,62 @@ namespace Vocaluxe.Base
{
_BackgroundMusicStreams.Add(CSound.Load(file));
}
_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);
}
CSound.FadeAndStop(_BackgroundMusicStreams[_CurrentStreamListIndex], CConfig.BackgroundMusicVolume, CConfig.FadeTime);
}
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;
}
}
}
}
+1
View File
@@ -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);