Solved

How to play MIDI files

Posted on 1998-10-25
6
628 Views
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.
0
Comment
Question by:mmarvi
  • 4
6 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility

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);
begin
 with MediaPlayer1 do
  if NotifyValue = nvSuccessful then begin
   Notify := True;
  Play;
 end;
end;
0
 

Author Comment

by:mmarvi
Comment Utility
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.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
Hello mmarvi
sorry
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
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 17

Expert Comment

by:inthe
Comment Utility
hello again  
this page may be of more help to you

http://www.compguy.com/cwtip05.htm
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
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
0
 

Accepted Solution

by:
tothpaul earned 60 total points
Comment Utility
try this !
-------------
unit sound;

interface

uses
 windows,mmsystem;

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

implementation

const
 playing:boolean=false;
Var
 DevId:word;
 mciPlay:TMCI_PLAY_PARMS;

procedure StartSound(hwnd:THandle;FileName:string);
 var
  mciOpen:TMCI_OPEN_PARMS;
 begin
  if playing then StopSound;
  with mciOpen do begin
   dwCallBack:=0;
   lpstrDeviceType:=nil;
   lpstrElementName:=PChar(FileName);
   lpstrAlias:=nil;
  end;
  if mciSendCommand(0, mci_Open, mci_open_element, Longint(@mciOpen))=0 then begin
   DevId:=mciOpen.wDeviceId;
   mciPlay.dwCallBack:=HWnd;
   mciPlay.dwFrom    :=0;
   Playing:=(mciSendCommand( DevID, mci_Play, mci_notify or mci_from, Longint(@mciPlay))=0);
   if not playing then StopSound;
  end;
 end;

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

procedure StopSound;
 begin
  mciSendCommand( DevID, mci_Close, 0, 0);
  playing:=false;
 end;

end.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now