how to play MP3 files

Discussion in 'ASP .Net' started by Andrew, Mar 8, 2008.

  1. Andrew

    Andrew Guest

    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
    Andrew, Mar 8, 2008
    #1
    1. Advertising

  2. Andrew

    TAB Guest

    //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" <> skrev i meddelandet
    news:...
    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
    TAB, Mar 24, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Dyer
    Replies:
    6
    Views:
    19,820
    Knute Johnson
    Jan 22, 2006
  2. Asle Frantzen

    Mp3-player - how to play an mp3?

    Asle Frantzen, Jul 8, 2003, in forum: C++
    Replies:
    5
    Views:
    659
    Kelsey Bjarnason
    Jul 22, 2003
  3. Adam Endicott

    play mp3 files from python

    Adam Endicott, Oct 25, 2003, in forum: Python
    Replies:
    9
    Views:
    7,318
  4. el chupacabra
    Replies:
    1
    Views:
    357
    Lucas Raab
    Aug 27, 2005
  5. HY Tech
    Replies:
    0
    Views:
    609
    HY Tech
    Sep 7, 2003
Loading...

Share This Page