diff options
| author | Michael VanOverbeek <[email protected]> | 2017-05-21 13:05:31 +0000 |
|---|---|---|
| committer | Michael VanOverbeek <[email protected]> | 2017-05-21 13:05:31 +0000 |
| commit | 68785f73f027b9dd4555b9f1ab7a22a1ca8794f8 (patch) | |
| tree | f0c6dea13195bc516f90c2aa29cf85fa1488f6cf /ShiftOS.WinForms/AudioManager.cs | |
| parent | 76b54853ba726179f9fddb30c6f838991b7aa71a (diff) | |
| parent | 9999324bd7751f536741c108322766421dae1a52 (diff) | |
| download | shiftos_thereturn-68785f73f027b9dd4555b9f1ab7a22a1ca8794f8.tar.gz shiftos_thereturn-68785f73f027b9dd4555b9f1ab7a22a1ca8794f8.tar.bz2 shiftos_thereturn-68785f73f027b9dd4555b9f1ab7a22a1ca8794f8.zip | |
Merge branch 'master' of https://github.com/shiftos-game/ShiftOS
I should hire Ash Ketchum to do this for me. He'd do a better job.
Diffstat (limited to 'ShiftOS.WinForms/AudioManager.cs')
| -rw-r--r-- | ShiftOS.WinForms/AudioManager.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/AudioManager.cs b/ShiftOS.WinForms/AudioManager.cs index 5c43ac4..ec12614 100644 --- a/ShiftOS.WinForms/AudioManager.cs +++ b/ShiftOS.WinForms/AudioManager.cs @@ -24,8 +24,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace ShiftOS.WinForms @@ -37,5 +39,78 @@ namespace ShiftOS.WinForms { } + + internal static byte[] GetRandomSong() + { + var r = new Random().Next(1, 10); + switch (r) + { + case 1: + return Properties.Resources.Ambient1; + case 2: + return Properties.Resources.Ambient2; + case 3: + return Properties.Resources.Ambient3; + case 4: + return Properties.Resources.Ambient4; + case 5: + return Properties.Resources.Ambient5; + case 6: + return Properties.Resources.Ambient6; + case 7: + return Properties.Resources.Ambient7; + case 8: + return Properties.Resources.Ambient8; + default: + return Properties.Resources.Ambient9; + + } + } + + internal static void StartAmbientLoop() + { + var athread = new Thread(() => + { + MemoryStream str = null; + NAudio.Wave.Mp3FileReader mp3 = null; + NAudio.Wave.WaveOut o = null; + bool shuttingDown = false; + + Engine.AppearanceManager.OnExit += () => + { + shuttingDown = true; + o?.Stop(); + o?.Dispose(); + mp3?.Close(); + mp3?.Dispose(); + str?.Close(); + str?.Dispose(); + }; + while (shuttingDown == false) + { + str = new MemoryStream(GetRandomSong()); + mp3 = new NAudio.Wave.Mp3FileReader(str); + o = new NAudio.Wave.WaveOut(); + o.Init(mp3); + bool c = false; + o.Play(); + o.PlaybackStopped += (s, a) => + { + c = true; + }; + while (!c) + { + try + { + o.Volume = (float)Engine.SaveSystem.CurrentSave.MusicVolume / 100; + } + catch { } + Thread.Sleep(10); + } + } + }); + athread.IsBackground = true; + athread.Start(); + } } } |
