aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/AudioManager.cs
diff options
context:
space:
mode:
authorwilliam341 <[email protected]>2017-05-28 12:37:00 -0700
committerGitHub <[email protected]>2017-05-28 12:37:00 -0700
commit771c20cfb3a703e0f1550fdcf9eb07b78298c944 (patch)
tree59cb532e15ebff313fdba2be264d78ec0033f407 /ShiftOS.WinForms/AudioManager.cs
parent496b0cbf8659c99203f48210fd39c572400ae623 (diff)
parentc7ba7d733c756d196f98dd4533289a1ef4db715f (diff)
downloadshiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.gz
shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.tar.bz2
shiftos_thereturn-771c20cfb3a703e0f1550fdcf9eb07b78298c944.zip
Merge pull request #1 from shiftos-game/master
welp, no longer a dev.
Diffstat (limited to 'ShiftOS.WinForms/AudioManager.cs')
-rw-r--r--ShiftOS.WinForms/AudioManager.cs75
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();
+ }
}
}