Search code examples
c#macosaudioxamarinplaysound

Sound player not playing sound


So I have a simple little program that needs to run a background sound while the user is doing other stuff. I wrote a simple code following other peoples tutorials and stuff on soundplayer. The problem is When I do soundplayer.Play(); no sound is played. Here is the code I used.

        private static SoundPlayer backgroundsound = new SoundPlayer("background1.wav");
        backgroundsound.Load();
        do{

            c_wait(0.01);}while(!backgroundsound.IsLoadCompleted);
        backgroundsound.PlayLooping ();
        //rest of program runs here
        loaddata ();

I am on a mac and using xamarin. No errors show up at all. I have no clue what is wrong.


Solution

  • Ensure that the file that you are attempting to load is actually being loaded given the name and directory. Check where the sound api checks for the file (most likely in the program's folder).

    Are you sure that your library supports .wav files? That may sound silly but I've seen stranger.

    Maybe you're playing the sound in your loop too often and it's repeating as soon as it plays.

    Those are a few possible solutions I can give, good luck on fixing your bug!