Solved

About playing midi in background

Posted on 1998-12-10
4
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert a string into a TDateTime 5 72
Delphi inherited method 6 80
Why is there a Difference between the SQL String and using the Parameter ? 7 56
MS Access from Delphi 31 81
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…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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