Problems with Songs and the Content Pipeline Tool

Ok I was working on my game last weekend and I ran into a brick wall when it came to Songs. The two problems I would encounter would be that songs did not play more then once (I could force them to work by calling play twice but thats clearly not ideal) and volume changes would always be ignored the first time playing a song.(Oddly except the first song heard) I carefully walked through the execution and while I saw some strange behaviour on the MediaPlayer.PlayPosition (Which we dont have the ability to change for some reason?) the volume would always show correctly- and the state (playing/stopped) was always good.

I did some searches here on the forums and I saw alot of issues which seemed very similar to the point that Im fairly confident those fixes would fix my issues as well. However… those fixes arent on any stable build yet. I tried installing the most recent unstable build (3.5.0.1288)- but while I can compile and run my game and (non song) assets as was, the content pipeline tool refuses to build. I click build or rebuild and nothing happens. I even created a brand new project, brought in a single texture and it still refuses to build.

Has anyone else tried this build- and if so have they been able to use the content pipeline tool?
Does anyone have any suggestions of a specific build I should grab that has the audio fixes?

The full 3.5 version cant come too soon =(

Thanks

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!

Thanks for the reply- I hadn’t considered using the sound effect classes for music but its true that I havent had the same issues with them. I will rework my audio class and give that a shot today =)

That completely worked- huge thanks Christoper! Its so great to finally have this dealt with =)

Awesome!

Yeah, I remember having the same problem with the Songs not playing right for me or not working at all…

On a different subject, I’m in the process of trying to get ready for a Greenlight launch at some point (not sure about the exact date yet) for a game I am making called Valgoria. It’s a tribute to some of my favorite SNES action rpgs.

I just got a website going with a blog…

here is the site

It would be awesome if you joined my blog by sending your email to my email, which is on the site. (details on the blog page)

Also, I am also interested in the game that you are making. So anything you want to send me about it, or if you have any more problems, you can contact me (posting on the forums is the best way for everyone to get benefits of help)

I’m just trying to get a network of support together for the day that I put my game on Greenlight, so joining my blog will really help!

Cool- Ill send an email your way today. Im definetly a fan of rpgs so Ill keep an eye on your project =)

I was just looking up whether Zelda is an RPG, and there was some dispute over it… I suppose my game, which is SNES Zelda-ish, maybe more of an Action Adventure rather than a RPG. Back in the day, when I played it in the 1990s for the first time, I know it was considered an RPG…

Your last comment made me analyze the categorization of the game more, and I don’t want to misrepresent it!

But nevertheless, I hope I can still have the support!

God bless and good day!