aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/AudioManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS_TheReturn/AudioManager.cs')
-rw-r--r--ShiftOS_TheReturn/AudioManager.cs68
1 files changed, 48 insertions, 20 deletions
diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs
index a636497..0a1a210 100644
--- a/ShiftOS_TheReturn/AudioManager.cs
+++ b/ShiftOS_TheReturn/AudioManager.cs
@@ -47,9 +47,12 @@ namespace ShiftOS.Engine
/// </summary>
public static void Stop()
{
- _out?.Stop();
- _reader?.Dispose();
- _out?.Dispose();
+ Desktop.InvokeOnWorkerThread(() =>
+ {
+ _out?.Stop();
+ _reader?.Dispose();
+ _out?.Dispose();
+ });
}
/// <summary>
@@ -80,16 +83,29 @@ namespace ShiftOS.Engine
/// <param name="file">The file to play.</param>
public static void Play(string file)
{
- try
+ bool play = true;
+ float volume = 1f;
+ if (SaveSystem.CurrentSave != null)
{
- _reader = new AudioFileReader(file);
- _out = new WaveOut();
- _out.Init(_reader);
- _out.Volume = _provider.Volume;
- _out.Play();
- _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); };
+ play = (SaveSystem.CurrentSave.SoundEnabled);
+ volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f;
+ }
+ if (play)
+ {
+ try
+ {
+ _reader = new AudioFileReader(file);
+ _out = new WaveOut();
+ _out.Init(_reader);
+ _out.Volume = volume;
+ _out.Play();
+ _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); };
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine("Audio error: " + ex.Message);
+ }
}
- catch { }
}
/// <summary>
@@ -98,15 +114,27 @@ namespace ShiftOS.Engine
/// <param name="str">The stream to read from.</param>
public static void PlayStream(Stream str)
{
- var bytes = new byte[str.Length];
- str.Read(bytes, 0, bytes.Length);
- ShiftOS.Engine.AudioManager.Stop();
- if (File.Exists("snd.wav"))
- File.Delete("snd.wav");
- File.WriteAllBytes("snd.wav", bytes);
-
- ShiftOS.Engine.AudioManager.Play("snd.wav");
-
+ try
+ {
+ bool play = true;
+ float volume = 1f;
+ if (SaveSystem.CurrentSave != null)
+ {
+ play = (SaveSystem.CurrentSave.SoundEnabled);
+ volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f;
+ }
+ if (play)
+ {
+ ShiftOS.Engine.AudioManager.Stop();
+ _out = new WaveOut();
+ var mp3 = new WaveFileReader(str);
+ _out.Init(mp3);
+ _out.Volume = volume;
+ _out.Play();
+ _out.PlaybackStopped += (o, a) => { PlayCompleted?.Invoke(); };
+ }
+ }
+ catch { }
}
public static event Action PlayCompleted;