需要在 .NET 应用程序中播放 mp3 文件方面的帮助吗?
我的要求是: - 单击按钮即可播放 mp3 文件 - 提供一个选项来寻找特定时间
我所经历的几乎所有教程/资源都使用“.wav”文件来播放声音。但我需要在应用程序中播放“.mp3”文件,最好不使用任何第 3 方库(NAudio、BASS 等)。我期望,可以使用 System.Media 命名空间的可用类来完成。
.wav 文件和 .mp3 文件有什么区别?它们是否以不同的方式编码,并且需要不同的媒体插件来播放?
因此,任何有关 mp3 文件的帮助将不胜感激。谢谢。
My requirements are:
- play a mp3 file on button click
- provide a option to seek to a particular time
Almost all of the tutorials/resources that I came through, used ".wav" files to play the sound. But I need to play a ".mp3" file within the application, preferably without using any 3rd party library(NAudio, BASS, etc). I expect, it can be done using the available classes of the System.Media namespace.
What is the difference between a .wav file and .mp3 file? Are they encoded in different manner, and need different media plugins to be played?
So any help regarding mp3 files would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不相信 System.Media 支持 MP3 文件。假设您使用的是 Windows,一种可能的方法是通过在“添加引用”对话框中添加对“Windows Media Player”的 COM 引用来使用 Windows Media Player API。然后添加一个 using 指令:
然后实例化该类:
然后您可以通过调用来播放音乐文件:
这个 open 方法似乎会在打开媒体文件后自动播放它,但是有显式的
Play()
和Stop()
等方法,您可以根据自己的喜好自定义此行为。XNA 框架还能够播放音乐文件,因为某些烦人的原因不允许包含空格,因此如果打算在 PC 上使用,我建议您使用 Windows Media Player API。
我希望这能让您朝着正确的方向前进!
I don't believe System.Media supports MP3 files. Assuming you are using Windows, a possible approach could be to use the Windows Media Player API by adding a COM reference to "Windows Media Player" in the Add Reference dialog. Then add a using directive:
and then instantiate the class:
You can then play music files by calling:
This open method seems to automatically play the media file once it is opened, however there are explicit
Play()
andStop()
etc methods you can use to customise this behaviour to your liking.The XNA framework also has ability to play music files using isn't allowed to contain spaces for some annoying reason so I recommend you use the Windows Media Player API if this is intended to be used on a PC.
I hope this has put you in the right direction!