aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/AudioManager.cs
diff options
context:
space:
mode:
authorwilliam341 <[email protected]>2017-06-29 13:13:45 -0700
committerwilliam341 <[email protected]>2017-06-29 13:13:45 -0700
commitad387c41e7d6cc547431e88695d4723ea2dba913 (patch)
treea68282dda40c4f0b28883241c7adcf9010f4550e /ShiftOS_TheReturn/AudioManager.cs
parentb4b19e7a4d203b58537f5b98214296ab52c49b2d (diff)
parent5bebd4411bc6266cbee482a429ba794eefa8f9b6 (diff)
downloadshiftos_thereturn-ad387c41e7d6cc547431e88695d4723ea2dba913.tar.gz
shiftos_thereturn-ad387c41e7d6cc547431e88695d4723ea2dba913.tar.bz2
shiftos_thereturn-ad387c41e7d6cc547431e88695d4723ea2dba913.zip
Merge remote-tracking branch 'refs/remotes/shiftos-game/master'
Diffstat (limited to 'ShiftOS_TheReturn/AudioManager.cs')
-rw-r--r--ShiftOS_TheReturn/AudioManager.cs54
1 files changed, 12 insertions, 42 deletions
diff --git a/ShiftOS_TheReturn/AudioManager.cs b/ShiftOS_TheReturn/AudioManager.cs
index 0950b55..a9101b7 100644
--- a/ShiftOS_TheReturn/AudioManager.cs
+++ b/ShiftOS_TheReturn/AudioManager.cs
@@ -83,28 +83,15 @@ namespace ShiftOS.Engine
/// <param name="file">The file to play.</param>
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,31 +101,14 @@ namespace ShiftOS.Engine
/// <param name="str">The stream to read from.</param>
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)
- {
- while(_out.PlaybackState == PlaybackState.Playing)
- {
- Thread.Sleep(10);
- }
- 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;