No sound playing
I am creating a game and using System.Media.SoundPlayer() to play a sound.
It works nicely when running from Visual Studio. But If I double click the .exe the sound isn't heard. Like:
No errors, which means it fines the file and runs it but I hear no sound. Any ideas?
mPlayer = new System.Media.SoundPlayer();
mPlayer.SoundLocation = "Sounds\\Sword.wav";
Are you sure it finds the file? (Does .Play() kill your whole program if the file isn't found? I don't see any other checks.)
If the sound isn't found, or has the wrong format it kills the program. Rather throws an unhandled exception with an error message. So I guess it does found the file. I also run it from the destination it is compiled/created, so there is no reason not to find the file.
Maybe your call to LoadAsync doesn't complete by the time you try to play the sound.
Maybe not the problem, but your relative path is dependent on the working directory. I suggest using something like:
var SoundFileName = System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, "Sounds\\Sword.wav");
That crashes the program. I gives:
@"C:\Documents and Settings\Alx\My Documents\Visual Studio 2008\Projects\dd\dd\bin\Debug\dd.exe\Sounds\Sword.wav";
But in any case I replace the above and put the exact location:
@"C:\Documents and Settings\Alx\My Documents\Visual Studio 2008\Projects\dd\dd\bin\Debug\Sounds\Sword.wav";
And get the same thing. No sound
I changed the LoadAsync() and the I get the same thing I again. I can see that it doesn't loads asynchronously (it has a delay), put I can hear no sound!
I really have no idea why.
It is called once actually at an "initialization point". So it has enough time I guess.
Originally Posted by valaris
Fixed. With the old good method. Restart Windows. Now the firewall asks tells me that the program tries to access the Service Manager. If I block it doesn't play the sound, but runs normally. If I don't block then it runs normally with sound.
Before it didn't ask me (ah, ah, windows....)
It probably did, just so long ago that you don't remember! At least if you are like me and don't reboot the machine unless absolutely NECESSARY.
Originally Posted by C_ntua
Maybe, mabye. Yeah, the desktop never closes. And by restart I meant "log off" :). Which is extremely usefull option to restore all kind of bugs. It kills everything and begins again without requiring waiting 2min for reboot.
A waste of energy because we are bored to open/close the PC. Shame on us
As for the faulty path, I forgot the call to System.IO.Path.GetDirectoryName on Location.