2020-11-18 16:26:21 +00:00
|
|
|
|
using Microsoft.Xna.Framework.Audio;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace SemiColinGames {
|
|
|
|
|
public class MusicPlayer : IDisposable {
|
|
|
|
|
|
2021-07-16 01:00:43 +00:00
|
|
|
|
public static bool Enabled = true;
|
2021-07-12 19:27:29 +00:00
|
|
|
|
|
2020-11-18 16:26:21 +00:00
|
|
|
|
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() {
|
2021-07-12 19:27:29 +00:00
|
|
|
|
if (Enabled) {
|
|
|
|
|
music?.Play();
|
|
|
|
|
}
|
2020-11-18 16:26:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|