1

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.

MrClan
  • 6,402
  • 8
  • 28
  • 43
  • 1
    A WAV file is an Uncompressed Audio File and as you could mention it larger than MP3 file based on size ,where MP3 (usually associated with MPEG-2 or MPEG Video Stream's) is a compressed Audio File (Algorithm from Moving Picture Expert Group) .So i don't think there are Filter's and/or classes integrated into Windows SDK which can do this for you.If you want you can play this file using Windows Media Player Control for C#. – Rosmarine Popcorn Sep 08 '11 at 13:00

1 Answers1

2

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:

using MP = MediaPlayer;

and then instantiate the class:

MP.MediaPlayer mediaPlayer = new MP.MediaPlayer();

You can then play music files by calling:

mediaPlayer.Open("filename.mp3");

This open method seems to automatically play the media file once it is opened, however there are explicit Play() and Stop() 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!

Scott
  • 999
  • 7
  • 13
  • Following the same logic, there's also the free[bass](http://www.un4seen.com/) player with a [Bass.Net](http://www.bass.radio42.com/) wrapper that's free for non-commercial use. (Registration is free and is used by open source projects like [MediaPortal](http://team-mediaportal.com). (edit: just saw the part of the question stating no third libraries...) – Joshua Sep 08 '11 at 14:48
  • 1
    At the end, NAudio was the better and more appropriate solution for me!!! It is one, really great, audio library!!! – MrClan Sep 13 '11 at 06:16