c# 如何播放多个 .wav 文件,并设置每个文件的音量
我目前正在使用 c#,我希望在后台播放一些音乐,并在用户按下按钮或发生其他小动作时发出其他小声音。 (具体来说,我正在制作一个小游戏,使用mogre3d,我只是需要添加一点声音)。
1) C# 中是否有内置方法可以同时播放多个 wav 文件?我尝试过使用 System.Media.SoundPlayer,但一次只能播放一个 wav 文件(并且我无法设置播放的音量)。
2)一次播放多个声音并能够设置每个声音音量的最佳/最简单方法是什么?
我对 C# 非常陌生,我确信它们一定是一个我没有看到的简单解决方案。它不需要是 wav,它可以很容易地是 mp3/等。但解决方案越简单越好。
非常感谢您的宝贵时间!
I am currently playing around in c#, and I would like to have some music play in the background and to have other little sounds happen when a user hits a button or when other little actions take place. (specifically, I am making a small game, using mogre3d, and I am just to the point in which I need to add a little sound).
1) Is there a way already built in to c# to play multiple wav files at the same time? I have tried using System.Media.SoundPlayer, but that can only play one wav file at a time (and I can not set the volume in which it is played).
2) What is the best/easiest way to play multiple sounds at a time and to be able to set each of the sounds volume?
I am dreadfully new to C#, and I am sure their must be a simple solution that I am just not seeing. It does not need to be wav, it can easily be mp3/et al. but the simpler the solution the better.
Thanks kindly for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速
使用该方法更改总体音量:http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/42b46e40-4d4a-48f8-8681-9b0167cfe781,您可以同时播放 .wav 文件单独的 SoundPlayer 实例。
更好且独立的卷
我会使用Bass.Net。良好的文档且简单。
Fast
Change overall volume with that method: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/42b46e40-4d4a-48f8-8681-9b0167cfe781 and you can play .wav files simultaneously with separate SoundPlayer instances.
Better and seperate Volumes
I would use Bass.Net. Good documentation and simple.
您可以使用 System.Media.SoundPlayer 类同时播放多个 .wav 文件:为此,只需为要播放的每个 .wav 文件创建一个 soundPlayer 实例即可。但您无法通过这种方式单独设置音量。
如果您想要更多音频文件功能,我建议您查看 NAudio 库。
You can play multiple .wav files simultaneously with the
System.Media.SoundPlayer
class: for this, just create an instance of soundPlayer for each .wav file you wish to play. But you cannot set the volume independently this way.If you want more functionalities with audio files, I recommend you check the NAudio library.