how to play MP3 files

A

Andrew

Hi,

Sorry for crosspost.

I need to play MP3 files from my .NET 2.0 SP1 C# WinForm app.

I tried referencing Microsoft.DirectX.AudioVideoPlayback; and creating Audio class for playback. But I get the following error which is beyod my ability to comprehend.

[
DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
]

How do I do this. Please help.

- Andrew
 
T

TAB

//Hi, I am using this for playing mp3 and wav. I think I found the example
at Codeproject.com
//Use

Player play = new Player();
play.Open(filename);
play.Play(false); //true for repeat, false for once;
play.Close(); // to stop

//To use the MCI Functions we have to import the winmm.dll.
//Then you go to the MSDN look up a command and its party time.
public class Player
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,
StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);

private string Pcommand;
private bool isOpen;

public Player()
{
}

public void Close()
{
Pcommand = "close MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = false;
}

public void Open(string sFileName)
{
Pcommand = "open \"" + sFileName + "\" type mpegvideo alias
MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
isOpen = true;
}

public void Play(bool loop)
{
if (isOpen)
{
Pcommand = "play MediaFile";
if (loop)
Pcommand += " REPEAT";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
}
// Returns the current status player: playing,paused,stopped
etc.
public string Status()
{
int i = 128;
System.Text.StringBuilder stringBuilder = new
System.Text.StringBuilder(i);
mciSendString("status MediaFile mode", stringBuilder, 128,
IntPtr.Zero);
return stringBuilder.ToString();
}

}
"Andrew" <[email protected]> skrev i meddelandet
Hi,

Sorry for crosspost.

I need to play MP3 files from my .NET 2.0 SP1 C# WinForm app.

I tried referencing Microsoft.DirectX.AudioVideoPlayback; and creating Audio
class for playback. But I get the following error which is beyod my ability
to comprehend.

[
DLL
'C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll'
is attempting managed execution inside OS Loader lock. Do not attempt to run
managed code inside a DllMain or image initialization function since doing
so can cause the application to hang.
]

How do I do this. Please help.

- Andrew
 

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top