在 WinForm 应用程序中播放 MP3 文件

编程入门 行业动态 更新时间:2024-10-27 08:30:23
本文介绍了在 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#:

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 文件

本文发布于:2023-11-23 15:36:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1621974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   文件   WinForm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!