简体   繁体   中英

System.Media.SoundPlayer not playing default nor other sounds

Im using Jetbrains rider as IDE and coding in C#; When im trying to compile the SoundPlayer class, im getting no sound nor the default sound. My code looks as following:

public static void Main(string[] args) {

        const string introSongLocation =
            @"/Users/niller/DragonBallZ_GameFolder/Sounds/introToGame.wav";

        var sound = new System.Media.SoundPlayer(introSongLocation);


        sound.Load();
        sound.Play();

        System.Console.WriteLine(sound.IsLoadCompleted);
        System.Console.WriteLine(sound.SoundLocation);
        System.Console.ReadLine();
    }

Output to terminal: 
true
/Users/niller/DragonBallZ_GameFolder/Sounds/introToGame.wav

As you can tell in the following code, I am checking if the sound is loaded probably, but otherwise if it was not the SoundPlayer.Play() method would have played the default sound, as explained in .

Therefore I ask:
Is it not enough to give the path for the wav sound file, and then load it in, or do I have to put the wav file in my solution folder? Nothing has seemed to work so far.

Solution:
I was using a MacBook, while the library only works on Windows and Linux.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM