From 8621b3ddffdd8211604f01d90ff40c9b2991f27a Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 24 Jun 2017 14:41:45 -0400 Subject: breaking the bonds storyline --- ShiftOS_TheReturn/AudioManager.cs | 58 ++++++++------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'ShiftOS_TheReturn/AudioManager.cs') diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs index 85e1371..a9101b7 100644 --- a/ShiftOS_TheReturn/AudioManager.cs +++ b/ShiftOS_TheReturn/AudioManager.cs @@ -83,28 +83,15 @@ namespace ShiftOS.Engine /// The file to play. public static void Play(string file) { - bool play = true; - float volume = 1f; - if (SaveSystem.CurrentSave != null) + try { - play = (SaveSystem.CurrentSave.SoundEnabled); - volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f; + var bytes = File.ReadAllBytes(file); + var str = new MemoryStream(bytes); + PlayStream(str); } - if (play) + catch { - 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); - } + } } @@ -114,35 +101,14 @@ namespace ShiftOS.Engine /// The stream to read from. public static void PlayStream(Stream str) { - try + bool play = true; + if (SaveSystem.CurrentSave != null) + play = SaveSystem.CurrentSave.SoundEnabled; + if (play) { - bool play = true; - float volume = 1f; - if (SaveSystem.CurrentSave != null) - { - play = (SaveSystem.CurrentSave.SoundEnabled); - volume = (float)SaveSystem.CurrentSave.MusicVolume / 100f; - } - if (play) - { - try - { - while (_out.PlaybackState == PlaybackState.Playing) - { - Thread.Sleep(10); - } - } - catch { } - 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(); }; - } + var splayer = new System.Media.SoundPlayer(str); + splayer.Play(); } - catch { } } public static event Action PlayCompleted; -- cgit v1.2.3