Solved

About playing midi in background

Posted on 1998-12-10
4
259 Views
Last Modified: 2010-04-04
How to play midi in background?
I mean like BGSOUND/EMBED in HTML, or like in SpeedDisk/
Norton Disk Doctor? And I want to loop that playing
until user out of program.
I don't want to use TMediaPlayer since it has its own
display. I don't want any display on my form.

Like usual, needs some guidance...

:-)

Stinger
0
Comment
Question by:stinger_60284
  • 2
4 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
hi,
you could always use tmedia and set visible property to false;
0
 
LVL 2

Accepted Solution

by:
Thaddy earned 20 total points
Comment Utility
To play it, load a wave file in memory and call:

SndPlaySound(PointertoWave, SND_ASYNC or SND_MEMORY or SND_LOOP);


to stop it call the same routine, but with the pointer set to nil:

SndPlaySound(nil,0);


0
 
LVL 2

Expert Comment

by:Thaddy
Comment Utility
Sorry, I misread the question this code is for waves,
here's code for midifiles, put it in a thread and you're away:
(btw:I didn't write this, but I forgot who did)
unit midi;

interface

uses
  Windows, mmsystem, Classes, SysUtils;

type
  TUMidi = class(TComponent)
  private
    { Private declarations }
    DeviceId:integer;
    fname:string;
  protected
    { Protected declarations }
  public
    { Public declarations }
    function Open:integer;
    function Play(fff,ttt:integer):integer;
    function Close:integer;
    function ErrStr(i:integer):String;
  published
    { Published declarations }
    property MidiFile: string read fname write fname;
  end;

procedure Register;

implementation

function TUMidi.Open:integer;
var
open_s:TMCI_OPEN_PARMS;
set_s:TMCI_SEQ_SET_PARMS;
a:array[0..512] of char;
begin
with open_s do
   begin
   lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_SEQUENCER);
   lpstrElementName:=StrPCopy(a,fname);
   end;
with set_s do
   begin
   dwTimeFormat:=MCI_FORMAT_MILLISECONDS;
   end;
result:=mciSendCommand(0,MCI_OPEN,
                       MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT,
                       DWORD(@open_s));
DeviceId:=open_s.wDeviceId;
if result<>0 then exit;
result:=mciSendCommand(DeviceId,MCI_SET,
                       MCI_SET_TIME_FORMAT,
                       DWORD(@set_s));

if result<>0 then self.close;
end;

function TUMidi.Play(fff,ttt:integer):integer;
var
play_s:TMCI_PLAY_PARMS;
begin
with play_s do
   begin
   dwFrom:=fff;
   dwTo:=ttt;
   end;
result:=mciSendCommand( DeviceID,MCI_PLAY,MCI_FROM or MCI_TO,
                        DWORD(@play_s));
end;

function TUMidi.Close:integer;
var
close_s:TMCI_GENERIC_PARMS;
begin
result:=mciSendCommand(DeviceId,MCI_CLOSE,
                       0,
                       DWORD(@close_s));
end;

function TUMidi.ErrStr(i:integer):string;
var s:array [0..256] of char;
begin
if mciGetErrorString(i,s,256)=false then
   result:='Undefined error code'
else
   result:=strpas(s);
end;


procedure Register;
begin
  RegisterComponents('Mid', [TMidi]);
end;

end.

0
 

Author Comment

by:stinger_60284
Comment Utility
Thanks Thaddy!!!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

13 Experts available now in Live!

Get 1:1 Help Now