在 WinForm 应用程序中播放 MP3 文件 [英] Playing a MP3 file in a WinForm application

查看:37
本文介绍了在 WinForm 应用程序中播放 MP3 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 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#:

http://www.daniweb.com/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:

http://social.msdn.microsoft.com/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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆