Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
275 views
Welcome To Ask or Share your Answers For Others

1 Answer

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");

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:

Building a Web Site with ASP .NET 2.0 to Navigate Your Music Library

Windows Media Object Model

Let the Music Play!

EDIT:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...