diff options
| author | Michael <[email protected]> | 2017-04-15 14:39:24 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-04-15 14:39:24 -0400 |
| commit | 51050a02d4d5eff361cfa697eeba777ddafa085a (patch) | |
| tree | 46fd8d57f8aa8a1c8a2eb264b7dd506f876c1c72 /ShiftOS_TheReturn/AudioManager.cs | |
| parent | 761202b4908d28f6aba852a3a59eb1dca50957d1 (diff) | |
| download | shiftos_thereturn-51050a02d4d5eff361cfa697eeba777ddafa085a.tar.gz shiftos_thereturn-51050a02d4d5eff361cfa697eeba777ddafa085a.tar.bz2 shiftos_thereturn-51050a02d4d5eff361cfa697eeba777ddafa085a.zip | |
Use NAudio to handle system sounds
Diffstat (limited to 'ShiftOS_TheReturn/AudioManager.cs')
| -rw-r--r-- | ShiftOS_TheReturn/AudioManager.cs | 62 |
1 files changed, 22 insertions, 40 deletions
diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 7466eeb..54ee1f1 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -42,58 +42,40 @@ namespace ShiftOS.Engine private static IAudioProvider _provider = null; private static bool _running = true; + public static void Stop() + { + _out?.Stop(); + _reader?.Dispose(); + _out?.Dispose(); + } + public static void Init(IAudioProvider _p) { -#if !NOSOUND _provider = _p; - AppearanceManager.OnExit += () => - { - _running = false; - _out?.Stop(); - _reader?.Dispose(); - _out?.Dispose(); - System.IO.File.Delete("temp.mp3"); - }; - var t = new Thread(() => - { - SaveSystem.GameReady += () => - { - while(_out == null) - { + } - } - _out.Volume = _provider.Volume; - }; - Random rnd = new Random(); - while(_running == true) + public static void SetVolume(float volume) + { + _provider.Volume = volume; //persist between songs + _out.Volume = volume; + } + + public static void Play(string file) + { + new Thread(() => + { + try { - int track = rnd.Next(0, _provider.Count); - byte[] mp3 = _provider.GetTrack(track); - System.IO.File.WriteAllBytes("temp.mp3", mp3); - _reader = new AudioFileReader("temp.mp3"); + _reader = new AudioFileReader(file); _out = new WaveOut(); _out.Init(_reader); _out.Volume = _provider.Volume; - _out.Play(); - while(_out.PlaybackState == PlaybackState.Playing) - { - Thread.Sleep(5000); //even when the player isn't playing, this will give a good delay between songs. - } - _reader.Dispose(); - _out.Dispose(); } - }); - t.IsBackground = true; - t.Start(); -#endif + catch { } + }).Start(); } - public static void SetVolume(float volume) - { - _provider.Volume = volume; //persist between songs - _out.Volume = volume; - } internal static void Kill() { |
