Is there a MIDI player in the library????

Dec 2, 2010 at 5:31 AM

Is there somekind of built in midi file player in the library? Or at least, is there a function -->midifile play?

Thank you,

Coordinator
Dec 2, 2010 at 7:20 AM

I'm afraid not. I started to wrap the midiOut APIs  long time ago but they are not ready to use. You would probably be better off embedding the Windows Media player COM object if possible.

Mark

Dec 2, 2010 at 7:02 PM

Thank you,

I'll probably code a few lines to use with the Naudio library and I'll post them on this forum. And, congratulations for your excellent library.

Dec 8, 2010 at 4:06 AM

I found a quick solution for a midi file player. The example is written for a console application but I've placed it in a form application and it works fine also. The only "requierement" the program needs is that you link the library.

In visual studio, go to 'project' -->'add reference'--> the 'COM' tab --> add library wmp.dll and msdxm.tlb (media player library). Don't forget to put a real midi file instead of my "example".

Here is the code:

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Media;

using System.IO;

namespace test_de_player_midi

{

   class Program

   {

       static void Main()

       {

           // A new player with the wmp.dll and msdxm.tlb library

           MediaPlayer.MediaPlayer mp = new MediaPlayer.MediaPlayer();  

          

           //The path. This was a simple midi example I wrote

            string the_midi_file = (Path.GetFullPath("C:/midi/test_midi_coll_changement tempo_filtre_voyetra.mid"));

 

            if (File.Exists(the_midi_file)) //Condition

           {

                //The midi file exist. We are in the 'IF'

               Console.WriteLine("The file --> " + the_midi_file + " exist! \n\nSO LISTEN!\n\n");

               try

               {

                  mp.FileName = the_midi_file;

                   mp.Open(the_midi_file);

                   mp.Play();

               }

               catch (Exception ex)  //Error-->exception

               {

                   //If error

                   Console.WriteLine("Midi File Trouble: {0} \r\n {1} \r\n {2}", the_midi_file, ex.Message,  ex.StackTrace);

               }

           }

           //An optional pause so the program does not stop. Press any key to end to program

           Console.ReadKey();

       }

   }

}