我正在开发一个 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 类的信息.但我读到 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 ?
任何帮助将不胜感激.
推荐答案下面的链接,给出了一个非常好的教程,关于用 c# 从 windows 窗体播放 mp3 文件:
The link below, gives a very good tutorial, about playing mp3 files from a windows form with c#:
www.daniweb/software-development/csharp/threads/292695/playing-mp3-in-c
此链接将引导您进入一个主题,其中包含有关如何使用 Windows 窗体播放 mp3 歌曲的大量信息.它还包含许多其他项目,试图实现相同的目标:
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:
social.msdn.microsoft/forums/en-US/csharpgeneral/thread/3dbfb9a3-4e14-41d1-afbb-1790420706fe
例如将此代码用于 .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.
例如将此代码用于 .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 文件
发布评论