45 lines
748 B
C#
45 lines
748 B
C#
using Microsoft.Xna.Framework.Audio;
|
|
using System;
|
|
|
|
namespace SemiColinGames {
|
|
public class MusicPlayer : IDisposable {
|
|
|
|
public static bool Enabled = true;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|