How to play MIDI files

Posted on 1998-10-25
Last Modified: 2010-04-06
I want to know how I can play a MIDI file in a Delphi 2.0 program using the Win32 MCI library. I know how to do it in Visual C++, but not in Delphi. Please include some code samples that clearly illustrate how to load and play a MIDI file, as well as send a notification to the form to restart the MIDI when it is done.
Question by:mmarvi
  • 4
LVL 17

Expert Comment

ID: 1344287

use the TMediaPlayer component
select file and set autoopen to true
and to loop it do the following on the notify event:

procedure TForm1.MediaPlayer1Notify(Sender: TObject);
 with MediaPlayer1 do
  if NotifyValue = nvSuccessful then begin
   Notify := True;

Author Comment

ID: 1344288
dear inthe:

I don't like your answer because I asked for information on how to use the Win32 MCI library to load and play a MIDI file. Please post an answer to that question and I'll be glad to give you points.
LVL 17

Expert Comment

ID: 1344289
Hello mmarvi
i can give you code for mci library playsound procedure
but it is for loading and playing wav files not midi
Im still looking for midi but everything i find is for wav :-(
im not sure how to do playsound procedure for midi files it may be the same but maybe not
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 17

Expert Comment

ID: 1344290
hello again  
this page may be of more help to you
LVL 17

Expert Comment

ID: 1344291
system.ini will hold the midi sequencer
on my system it's sequencer=mciseq.drv
so something like this is what your after i think

open sequencer!yoursong.mid alias anthem
play anthem
pause anthem
resume anthem
stop anthem
seek anthem to start
play anthem
stop anthem
close anthem

Accepted Solution

tothpaul earned 60 total points
ID: 1344292
try this !
unit sound;



procedure StartSound(hwnd:THandle; FileName:string);
procedure Replay;
procedure StopSound;



procedure StartSound(hwnd:THandle;FileName:string);
  if playing then StopSound;
  with mciOpen do begin
  if mciSendCommand(0, mci_Open, mci_open_element, Longint(@mciOpen))=0 then begin
   mciPlay.dwFrom    :=0;
   Playing:=(mciSendCommand( DevID, mci_Play, mci_notify or mci_from, Longint(@mciPlay))=0);
   if not playing then StopSound;

procedure Replay;
  if Playing then
   mciSendCommand( DevID, mci_Play, mci_notify or mci_from, Longint(@mciPlay));

procedure StopSound;
  mciSendCommand( DevID, mci_Close, 0, 0);



Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question