在WinForm应用程序播放MP3文件 [英] Playing a MP3 file in a WinForm application
问题描述
我开发一个的WinForm
应用程序。我想,当用户点击一个按钮来播放MP3文件。
I am developing a WinForm
application. I want to play a MP3 file when the user clicks a button.
通过MP3文件位于其中执行应用程序的计算机的文件系统中。结果,
我用Google搜索了一会儿,我发现关于 System.Media.SoundPlayer
类的信息。但我已阅读了声音播放
类只能用于以.wav格式的播放文件。
The MP3 file is located in the file system of the computer where the application is executed.
I have Googled for a while and I have found information about the System.Media.SoundPlayer
class. But I have read that the SoundPlayer
class can only be used to play files in .wav format.
什么类可用于mp3格式播放文件?
What classes can be used to play files in .mp3 format ?
任何帮助将大大AP preciated。
Any help will be greatly appreciated.
推荐答案
下面的链接,给出了一个非常好的教程,有关从窗口播放MP3文件形成用C#:
The link below, gives a very good tutorial, about playing mp3 files from a windows form with c#:
<一个href=\"http://www.daniweb.com/software-development/csharp/threads/292695/playing-mp3-in-c\">http://www.daniweb.com/software-development/csharp/threads/292695/playing-mp3-in-c
这个链接将带你到一个主题,包含有关如何播放MP3歌曲,使用Windows窗体了很多信息。它还包含了许多其他项目,努力实现同样的事情:
This link will lead you to a topic, which contains a lot information about how to play an mp3 song, using Windows forms. It also contains a lot of other projects, trying to achieve the same thing:
<一个href=\"http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/3dbfb9a3-4e14-41d1-afbb-1790420706fe\">http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/3dbfb9a3-4e14-41d1-afbb-1790420706fe
例如使用code为.MP3:
For example use this code for .mp3:
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = "My MP3 file.mp3";
wplayer.Controls.Play();
那么只有把wplayer.Controls.Play();在Button_Click事件。
Then only put the wplayer.Controls.Play(); in the Button_Click event.
例如使用code为.WAV:
For example use this code for .wav:
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = "Sound.wav";
player.Play();
把player.Play();在Button_Click事件,它将工作。
Put the player.Play(); in the Button_Click event, and it will work.
这篇关于在WinForm应用程序播放MP3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!