I have this problem where I can't stop the audio file from playing.
This is a snippet of my code:
private Sound bgMusic;
bgMusic = new Sound("bgMusic.wav");
if(gameHasStarted)
bgMusic.Play();
else
bgMusic.Stop();
I've searched Google mulptiple times, but without any success. The music just doesn't stop. I've tried threading this audio file, but without luck. I've also tried using a MediaPlayer - the sound always plays, whichever option I choose, but it just doesn't stop.
So my question: How do I stop audio file from playing? Do I need to reset it? Close it? Destroy it? How?!
It's actually not that difficult:
private System.Media.SoundPlayer playerMainMenu;
- initialize player
playerMainMenu = new System.Media.SoundPlayer("getlucky.wav");
- load file
playerMainMenu.PlayLooping();
- to play looping
playerMainMenu.Play();
- to play once
playerMainMenu.Stop();
- to stop this player
Works like a charm. Found by trial-and-error.
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.