2021-04-23 20:28:06 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SynthySound;
|
|
|
|
|
|
|
|
|
|
namespace EvilSatellites
|
|
|
|
|
{
|
|
|
|
|
public class MusicManager
|
|
|
|
|
{
|
2021-04-23 21:08:37 +02:00
|
|
|
public string CurrentFile;
|
2021-04-23 20:28:06 +02:00
|
|
|
public ISoundEffect Song;
|
|
|
|
|
public float _Volume;
|
|
|
|
|
public float Volume {
|
|
|
|
|
get => _Volume;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (IsPlaying)
|
|
|
|
|
{
|
2021-04-23 21:08:37 +02:00
|
|
|
Song.Volume = value;
|
2021-04-23 20:28:06 +02:00
|
|
|
}
|
2021-04-23 21:08:37 +02:00
|
|
|
_Volume = value;
|
2021-04-23 20:28:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool IsPlaying;
|
|
|
|
|
public Synthy Engine;
|
|
|
|
|
public MusicManager(Synthy engine)
|
|
|
|
|
{
|
|
|
|
|
Engine = engine;
|
|
|
|
|
_Volume = 0.2f;
|
|
|
|
|
IsPlaying = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Play(string path)
|
|
|
|
|
{
|
2021-04-23 21:08:37 +02:00
|
|
|
if (path == CurrentFile) return;
|
2021-04-23 20:28:06 +02:00
|
|
|
if (IsPlaying)
|
|
|
|
|
{
|
|
|
|
|
Song.Stop();
|
|
|
|
|
Song.Destroy();
|
|
|
|
|
}
|
|
|
|
|
Song = Engine.Load(@"sfx/music/" + path + ".mp3", false, true);
|
|
|
|
|
|
|
|
|
|
Song.Play();
|
|
|
|
|
Song.Volume = _Volume;
|
|
|
|
|
Song.Loop = true;
|
2021-04-23 21:08:37 +02:00
|
|
|
CurrentFile = path;
|
2021-04-23 20:28:06 +02:00
|
|
|
IsPlaying = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
if (IsPlaying)
|
|
|
|
|
{
|
|
|
|
|
Song.Stop();
|
|
|
|
|
Song.Destroy();
|
|
|
|
|
IsPlaying = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|