Solved

About playing midi in background

Posted on 1998-12-10
4
271 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 119
Delphi selector screen 2 84
Convert MS Word document to a PDF file 9 90
How to Get Images From Server using App Tethering 11 39
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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