Solved

About playing midi in background

Posted on 1998-12-10
4
262 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
ID: 1350453
hi,
you could always use tmedia and set visible property to false;
0
 
LVL 2

Accepted Solution

by:
Thaddy earned 20 total points
ID: 1350454
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
ID: 1350455
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
ID: 1350456
Thanks Thaddy!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

22 Experts available now in Live!

Get 1:1 Help Now