[英]Stop sound playback in C# with SDL library
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. 我已经多次搜索过Google,但没有成功。 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.
我也尝试过使用MediaPlayer-声音总是播放,无论我选择哪个选项,但声音不会停止。
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.
通过反复试验发现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.