sneak/Shared/MusicPlayer.cs

45 lines
749 B
C#

using Microsoft.Xna.Framework.Audio;
using System;
namespace SemiColinGames {
public class MusicPlayer : IDisposable {
public static bool Enabled = false;
private SoundEffectInstance music;
~MusicPlayer() {
Dispose();
}
public void Dispose() {
Stop();
music?.Dispose();
GC.SuppressFinalize(this);
}
public void Load(SoundEffect sound) {
if (sound == null) {
return;
}
music = sound.CreateInstance();
music.IsLooped = true;
music.Volume = 0.1f;
}
public void Stop() {
music?.Stop();
}
public void Pause() {
music?.Pause();
}
public void Play() {
if (Enabled) {
music?.Play();
}
}
}
}