How to play mp3 file in my program?

  • Thread starter Thread starter Liren Zhao
  • Start date Start date
You can use media player to play mp3 file. To invoke media player use
P/Invoke ShellExecuteEx (where just pass mp3 file) or CreateProcess
where you should specify media player as application that must be
executed and your mp3 file as argument. Also take a look at fmod
http://www.demsey.org/blog/default.aspx?date=2004-03-17

Best regards,
Sergey Bogdanov
 
Here's how you can do it on the .NET Framework

In your project add a reference to the ActiveMovie control type
library, it's on the COM tab.

Then use the followint code, where fileName is the name and path of
your MP3 file.

*************************
string fileName = @"C:\music.mp3";
QuartzTypeLib.FilgraphManager filgraphManager = new
QuartzTypeLib.FilgraphManager();
QuartzTypeLib.IMediaControl mediaControl =
(QuartzTypeLib.IMediaControl)filgraphManager;
mediaControl.RenderFile(fileName);
mediaControl.Run();
*************************
Also, you can use mediaControl.Stop() to stop playint the MP3
 
....and what good is that on the CF 1.0 where COM Interop doesn't exist?!

Cheers
Daniel
 
Sure... or wait for CF 2.0 that will support it out of the box...

Cheers
Daniel
 
Or use fmodce (www.fmod.org. Free for non-commercial use.

blurb: "FMOD supports 3d sound, midi, mods, mp3, ogg vorbis, wma, aiff,
recording, obstruction/occlusion, cd playback (analog or digital), cd
ripping, mmx, internet streaming, dsp effects, spectrum analysis, user
created samples and streams, synchronization support, ASIO, EAX 2&3,
C/C++/VB/Delphi and more."

Lane Kuo has written a very nice .NET CF wrapper in his smartphone alarm
project.
http://sourceforge.net/projects/spalarm/

The library can easily be extended to add support for the callbacks using
the standard technique of another native dll which posts messages to a
MessageWindow class in your .NET app.


fmodce is free for non commercial use and it rocks.
 
Sorry, a bit off topic. but can you expand on the "standard technique of
another native dll which posts messages to a MessageWindow class in your
..NET app"

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top