0
Answer

Playing mp3 via MCI

Ask a question
Phil Higgins

Phil Higgins

17y
3.3k
1
Hi there,

I've been trying to get mp3's to play using MCI in C#, however, no matter what I do they don't seem to play. I can play wav files fine using the same code, but the mciSendString() function returns the error "A problem occured ininitializing MCI" if i try to use mp3 files.

Here are the relevant parts of the code:

public void Open( String fileName, String alias, MM_TYPE type )
{
     bool alreadyExists = false;

     foreach( String s in aliases )
     {
          if( s.Equals( alias ) )
          {
               alreadyExists = true;
          }
     }

     if( !alreadyExists )
     {
          switch( type )
          {
               case MM_TYPE.CD_AUDIO:
               command = "open cdaudio!" + fileName + " alias " + alias ;
               break;

               case MM_TYPE.MIDI_AUDIO:
               command = "open sequencer!" + fileName + " alias " + alias ;
               break;

              m case MM_TYPE.WAVE_AUDIO:
               command = "open waveaudio!" + fileName + " alias " + alias ;
               break;

               case MM_TYPE.MP3_AUDIO:
               command = "open MPEGVideo!" + fileName + " alias " + alias;
               break;

          }

          SendString();
          aliases.Add( alias );
     }
}

private void SendString()
{
     StringBuilder errorBuffer = new StringBuilder( 128, 128 );
     int error= mciSendString( command, errorBuffer, 128, 0 );

     if( error != 0 )
     {
          int retval = mciGetErrorString( error, errorBuffer, 128 );
     }
}

Any suggestions on why this isn't working would be appreciated very much!

Thanks :)