如何播放声音文件 [英] How to play a sound file

查看:158
本文介绍了如何播放声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,如何播放(暂停,前进......)一个声音文件(MP3,OGG)?该文件可以是在硬盘上,或在互联网上。

With C#, How do I play (Pause, Forward...) a sound file (mp3, ogg)? The file could be on the hard disk, or on the internet.

是否有任何库或类,有可以缓解我的工作?

Is there any library or Class out there that can ease me the work ?

推荐答案

如果你不介意,包括 Microsoft.VisualBasic.dll中在你的项目,你可以这样来做:

If you don't mind including Microsoft.VisualBasic.dll in your project, you can do it this way:

var audio = new Microsoft.VisualBasic.Devices.Audio();
audio.Play("some file path");

如果你想要做更复杂的东西,我知道最简单的方法是使用在 Windows媒体播放器API 。您添加DLL,然后使用它。 API是一种笨重,但它的工作;我用它来使周围的Windows Media Player自己的音乐播放器的包装供个人使用。下面是一些有用的链接,让你开始:

If you want to do more complex stuff, the easiest way I know of is to use the Windows Media Player API. You add the DLL and then work with it. The API is kind of clunky, but it does work; I've used it to make my own music player wrapper around Windows Media Player for personal use. Here are some helpful links to get you started:

2.0建立一个网站用ASP .NET浏览您的音乐库

的Windows Media对象模型

让音乐播放!

编辑:

自从我写了这个,我已经找到了一个更简单的方法,如果你不介意,包括你的code WPF类。 WPF(.NET 3.0和前锋)有一个的MediaPlayer 类是围绕Windows媒体播放器的包装。这意味着你不必写自己的包装,这是很好的,因为,正如我上面提到的,WMP API是相当笨重,很难使用。

Since I wrote this, I've found an easier way, if you don't mind including WPF classes in your code. WPF (.NET 3.0 and forward) has a MediaPlayer class that's a wrapper around Windows Media Player. This means you don't have to write your own wrapper, which is nice since, as I mentioned above, the WMP API is rather clunky and hard to use.

这篇关于如何播放声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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