This might not answer your question directly, but when I play music in my game Valgoria I use this class that I built to play audio…
I am using a .wav file as the file I build into the project using the Monogame Pipeline tool
Add to your current project a class called AudioSupport and then copy this code into it and replace the code in it with the following, and don’t forget to replace “YourNameSpaceGoesHere” with whatever your namespace is…
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YourNameSpaceGoesHere
{
static public class AudioSupport
{
private static Dictionary<String, SoundEffect> sAudioEffects = new Dictionary<string, SoundEffect>();
private static SoundEffectInstance sBackgroundAudio = null;
private static SoundEffectInstance sCueAudio = null;
private static List<SoundEffectInstance> sCueAudioList = new List<SoundEffectInstance>();
public static String currentAudioString;
static private SoundEffect FindAudioClip(String name)
{
SoundEffect sound = null;
if (sAudioEffects.ContainsKey(name))
sound = sAudioEffects[name];
else
{
sound = Game1.content.Load<SoundEffect>(name);
if (null != sound)
sAudioEffects.Add(name, sound);
}
return sound;
}
static public void PlayACue(String cueName, float level)
{
if(sCueAudioList.Count > 50)
{
sCueAudioList.Clear();
}
SoundEffect sound = FindAudioClip(cueName);
if (null != sound)
{
sCueAudioList.Add(sound.CreateInstance());
sCueAudioList[sCueAudioList.Count - 1].IsLooped = false;
sCueAudioList[sCueAudioList.Count - 1].Volume = level;
sCueAudioList[sCueAudioList.Count - 1].Play();
}
}
static public void StartBg(String name, float level)
{
SoundEffect bgm = FindAudioClip(name);
sBackgroundAudio = bgm.CreateInstance();
sBackgroundAudio.IsLooped = true;
sBackgroundAudio.Volume = level;
sBackgroundAudio.Play();
}
static public void StopBg()
{
if (null != sBackgroundAudio)
{
sBackgroundAudio.Pause();
sBackgroundAudio.Stop();
sBackgroundAudio.Volume = 0f;
sBackgroundAudio.Dispose();
}
sBackgroundAudio = null;
}
static public void PlayBackgroundAudio(String bgAudio, float level)
{
currentAudioString = bgAudio;
StopBg();
if (("" != bgAudio) || (null != bgAudio))
{
level = MathHelper.Clamp(level, 0f, 1f);
StartBg(bgAudio, level);
}
}
}
}
Then whenever you want to play background music in your game just do this… in your game class…
AudioSupport.StartBg(“theNameOfTheMusicFile”, .5f);
the .5f is the level of volume…
remember NOT to include the extension! (in my case .wav)
There is a little bit of extra code in there (in the static class I provided) that I have been playing around with, so you can take out some of those methods if you would like and I’m sure it would still work…
Look at the different methods in the class and decide which ones you want to use, pass the appropriate parameters and viola… hopefully!
This class is a static class so you don’t have to instantiate it at the beginning of your Game class…
Just AudioSupport.WhateverMethodYouWant(Appropriate Parameters); and it should work…
AudioSupport.PlayACue(“fileName”, floatLevel);
is a good way to play a sound just once…
I started out trying to use Songs to play music too, but I found out that this way is better because it uses SoundEffects and SoundEffect Instances…
Hope this helps!