RV.
RV.

Reputation: 2842

play mp3 audiofile

I have written some code for playing a .wav through my application. Now I want to play a mp3 file through.

I have .NET framework 1.1

Upvotes: 0

Views: 352

Answers (3)

Larry Osterman
Larry Osterman

Reputation: 16142

I'd suggest using DirectShow - the RenderFile API is extremely simple. This site appears to show a managed wrapper for DShow (caveat programmer, I've not used it).

Edit to add: Personally I'd stay away from the MCI APIs if at all possible - they're extremely old APIs and they're not particularly reliable.

Upvotes: 1

Mark Heath
Mark Heath

Reputation: 49482

if you have .NET framework 1.1. only, probably your best approach is to use a P/Invoke wrapper for mciSendCommand

[DllImport("winmm.dll")]
private static extern long mciSendString(
        string strCommand, StringBuilder returnString, 
        int returnBufferLength, IntPtr callback);

void PlayFile(string mp3FileName)
{
    string deviceType = "MPEGVideo";
    string fileName = mp3FileName;
    string alias = "MyMp3File";
    string playCommand = string.Format("open \"{0}\" type {1} alias {2}",
                            fileName, deviceType, alias);
    mciSendString(playCommand, null, 0, IntPtr.Zero);
    playCommand = string.Format("play {0} from 0", alias);
    mciSendString(playCommand, null, 0, IntPtr.Zero);

    // send these when you are finished
    // playCommand = "stop MyMp3File";
    // playCommand = "close MyMp3File";
}

Upvotes: 3

weismat
weismat

Reputation: 7411

You can try NAudio. Otherwise you may consider to use a native library using Interop.

Upvotes: 1

Related Questions